Timed selector never performed

Posted by sudo rm -rf on Stack Overflow See other posts from Stack Overflow or by sudo rm -rf
Published on 2010-12-22T21:19:39Z Indexed on 2010/12/22 21:54 UTC
Read the original article Hit count: 112

Filed under:
|
|
|

I've added an observer for my method:

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

Then my relevant methods:

-(void)closeViewAfterUpdating; {
NSLog(@"Part 1 called");
[self performSelector:@selector(closeViewAfterUpdating2) withObject:nil afterDelay:2.0];
}

-(void)closeViewAfterUpdating2; {
NSLog(@"Part 2 called");
[self dismissModalViewControllerAnimated:YES];
}

The only reason why I've split this method into two parts is so that I can have a delay before the method is fired.

The problem is, the second method is never called. My NSLog output shows Part 1 called, but it never fires part 2. Any ideas?

EDIT: I'm calling the notification from a background thread, does that make a difference by any chance?

Here's how I'm creating my background thread:

[NSThread detachNewThreadSelector:@selector(getWeather) toTarget:self withObject:nil];

and in getWeather I have:

[[NSNotificationCenter defaultCenter] postNotificationName:@"updateZipLabel" object:textfield.text];

Also, calling:

[self performSelector:@selector(closeViewAfterUpdating2) withObject:nil];

does work.

EDITx2: I fixed it. Just needed to post the notification in my main thread and it worked just fine.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c