Iphone 其他类事件的NSNotification实现?

Iphone 其他类事件的NSNotification实现?,iphone,nsnotificationcenter,Iphone,Nsnotificationcenter,嗨 在我的ViewController.m中,我在“viewDidLoad”中添加了一个NSNotification,如下所示: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pageControlChanged:) notificat

在我的ViewController.m中,我在“viewDidLoad”中添加了一个NSNotification,如下所示:

        [[NSNotificationCenter defaultCenter] addObserver:self
                                    selector:@selector(pageControlChanged:) 
                                    notificationName:@"ScrollViewDidEnd"
   object:nil];
然后我有一个自定义的scrollView类“MyScrollView”,在这里我可以滚动图像。当调用“ScrollViewDiEndDecelling:(UIScrollView*)scrollView{..”方法时,我在那里添加了一个postNotification

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
[[NSNotificationCenter defaultCenter] postNotificationName:@"ScrollViewDidEnd" object:nil];
}
- (void) pageControlChanged:(NSNotification*)notification{
    NSLog(@"pagecontrol: %@", notification);

}
编译项目时,出现错误,应用程序崩溃: 控制台输出:“未找到addObserver:selector:notifcatonName:object:”方法

所以,这是我第一次使用NSNotification,如果能在这里得到一些帮助就太好了。 谢谢你抽出时间。
yosh

您正在寻找的方法是:

- (void)addObserver:(id)notificationObserver selector:(SEL)notificationSelector name:(NSString *)notificationName object:(id)notificationSender
(注意
名称:
,而不是
通知名称:

因此,您的代码应该是:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(pageControlChanged:)
                                             name:@"ScrollViewDidEnd"
                                           object:nil];