开发者

NSNotification-implementation for other class events?

HI,

in my ViewController.m i´ve added a NSNotification in "viewDidLoad" like this:

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

Then i´ve a custom scrollView-class "MyScrollView" where i can scroll an image. I´ve added a postNotification there, when the "scrollViewDidEndDecelerating:(UIScrollView *)scrollView{.." method is called.

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

}

When i compile my project, i get an error and the app crashes: Console-output: "No addObserver:selector:notifcatonName:object:" method found.

So, that´s my first NSNotification usage, would be great to开发者_JAVA技巧 get some help here. Thanks for your time. yosh


The method you're looking for is:

- (void)addObserver:(id)notificationObserver selector:(SEL)notificationSelector name:(NSString *)notificationName object:(id)notificationSender

(note the name:, not notificationName:)

So your code should be:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜