NSNotificationCenterの通知でMainThread実行
Notificationを使ってUIの更新をしたい場合、
NSNotificationCenterからperformSelectorOnMainThreadを呼んであげると良い。
例
NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; [center performSelectorOnMainThread:@selector(postNotification:) withObject:[NSNotification notificationWithName:@"name" object:nil] waitUntilDone:NO];
期待通りUIが更新される。
良くない例
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center postNotification:@"name"];
通常の呼び方だと新スレッドでメソッドが実行されるようなので、
これだとUIがうまく更新されない。