嗨,
在我的ViewController.m中,我在"viewDidLoad“中添加了一个NSNotification,如下所示:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(pageControlChanged:)
notificationName:@"ScrollViewDidEnd"
object:nil];然后我有一个自定义的scrollView类"MyScrollView“,我可以在其中滚动图像。我在那里添加了一个postNotification,当"scrollViewDidEndDecelerating:(UIScrollView *)scrollView{..“方法被调用。
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
[[NSNotificationCenter defaultCenter] postNotificationName:@"ScrollViewDidEnd" object:nil];
}
- (void) pageControlChanged:(NSNotification*)notification{
NSLog(@"pagecontrol: %@", notification);
}当我编译我的项目时,我得到了一个错误,应用程序崩溃了: Console-output:"No and :selector:notifcatonName:object:“方法找到。
所以,这是我第一次使用NSNotification,如果能在这里得到一些帮助就太好了。耽误您时间,实在对不起。yosh
发布于 2010-08-02 17:38:15
您要查找的方法是:
- (void)addObserver:(id)notificationObserver selector:(SEL)notificationSelector name:(NSString *)notificationName object:(id)notificationSender(注意name:,而不是notificationName:)
所以你的代码应该是:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(pageControlChanged:)
name:@"ScrollViewDidEnd"
object:nil];https://stackoverflow.com/questions/3386518
复制相似问题