I have a app that logs into a website. I had problems because I checked if I was logged in before the asynchronous web request finished. So I "solved" this using notification to notify when the web request finished, and then continuing to check if login was successful.
The problem now is that the callback to the selector eventHandler is never made, so nothing is happening.
Have I misunderstood the concept of notification or is there something else wrong?
The problem now is that the callback to the selector eventHandler is never made, so nothing is happening.
Code:
-(IBAction) login:(id)sender {
// Add notification to listen to
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(eventHandler)
name:@"requestFinished"
object:nil];
}
-(void)eventHandler:(NSNotification *) notification {
NSLog(@"LoginViewController: Request finished and event triggered");
}
Code:
// Posting notification that the web request finished
[[NSNotificationCenter defaultCenter]
postNotificationName:@"requestFinished" object:nil];