سؤال

keyboard = [[FTKeyboardHelper alloc] init];

I have a keyboard helper class, and would like to call the method keyboardShow that is defined inside the keyboard.

[[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(keyboard.keyboardShow:)
                                                     name:UIKeyboardWillShowNotification
                                                   object:nil];

However I get the error message Excepted : Any advice?

هل كانت مفيدة؟

المحلول

What about

[[NSNotificationCenter defaultCenter] addObserver:keyboard
                                             selector:@selector(keyboardShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];

I'm not sure you can "." Separate the selector, it's not a key path.


But I think that would be bad design, you should probably put that code inside your helper.
In the - init and unregister in the - dealloc or use a pair of - register and - unregistermethod to control this outside of the normal life cycle of your object.
But don't forget to unregister before the helper is deallocated, if not, you will crash the next time the keyboard shows up.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top