views:

54

answers:

1

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 get some help here. Thanks for your time. yosh

+1  A: 

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];
Nick Forge
Oh damn.. So silly. Thanks for that help. It works ;)
geforce