Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在类内为NSNotification选择选择器?_Ios_Ios7_Nsnotificationcenter - Fatal编程技术网

Ios 如何在类内为NSNotification选择选择器?

Ios 如何在类内为NSNotification选择选择器?,ios,ios7,nsnotificationcenter,Ios,Ios7,Nsnotificationcenter,我有一个键盘助手类,希望调用键盘中定义的方法keyboardShow keyboard = [[FTKeyboardHelper alloc] init]; 但是,我收到错误消息例外: 有什么建议吗 怎么样 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboard.keyboardShow:

我有一个键盘助手类,希望调用
键盘
中定义的方法
keyboardShow

keyboard = [[FTKeyboardHelper alloc] init];
但是,我收到错误消息
例外:
有什么建议吗

怎么样

[[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(keyboard.keyboardShow:)
                                                     name:UIKeyboardWillShowNotification
                                                   object:nil];
我不确定您是否可以“.”分隔选择器,它不是关键路径


但我认为这将是一个糟糕的设计,您可能应该将该代码放在助手中。
-init
中,并在
-dealloc
中注销,或使用一对
-register
-unregister
方法将其控制在对象的正常生命周期之外。

但是不要忘记在解除分配帮助程序之前取消注册,否则,下次键盘出现时,您将崩溃。

+1关于将观察者放入键盘帮助程序类。我想那是个更好的主意。
[[NSNotificationCenter defaultCenter] addObserver:keyboard
                                             selector:@selector(keyboardShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];