我可以将观察者两次(偶然)添加到通知中心,我将收到两次通知。 是否有可能只获得一个通知?你知道更优雅的解决方案吗?NSNotificationCenter可能导致错误。你知道更优雅的解决方案吗?
我告诉你这个例子,因为这可能会导致错误。
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
}
- (void)keyboardDidShow:(NSNotification *)ntf
{
}
hm ..如果您多次写入任何其他相同的代码,也会导致错误。 – beryllium 2012-02-17 16:22:54