NSNotification stops method from working completely
I have this method:
- (void)reloadMessages:(NSNotification *)notification {
NSLog(@"RECIEVED NEW MESSAGES TO MessagesRootViewController");
// we need to get the threads from the database...
NSFetchRequest *theReq = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Thread" inManagedObjectContext:managedObjectContext];
[theReq setEntity:entity];
threads = [[managedObjectContext executeFetchRequest:theReq error:nil] retain];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New Message" message:@"New message" delegate:nil cancelButtonTitle:@"Thanks" otherButtonTitles:nil];
[alert show];
[alert release];
[self.tableView reloadData];
}
If I call [self reloadMessages:nil]
then the function works exactly as prescribed above.
If its called from an NSNotificationCenter notification: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadMessages:) name:@"newMessa开发者_开发问答gesArrived" object:nil];
then it gets to [alert show]
and stops with the screen dimmed as per this screenshot:
Any idea why this is happening?
If I take away the UIAlertView bit and just leave [self.tableView reloadData];
then it calls that function, but it stops at some point. NSLogging on the table view datasource methods reveals that the table view is updated with the correct number of rows (suggesting the core data request isn't causing a problem) but that cellForRowAtIndexPath
isn't being called.
The program isn't crashing. Without the alert view the table view doesn't quite reload completely as above, but the view is still useable and moving the table view causes the rows to update appropriately (as does going to the contacts tab and back again).
If you need any more information then I can give you it.
Thanks for any help. :)
Tom
When you call the method from the NSNotificationCenter, the method is not on the GUI thread. You have to execute the AlertDialog show and TableView reloading on the GUI thread using performSelectorOnMainThread
精彩评论