静的ライブラリのデリゲート メソッドが起動された後、奇妙な問題が発生します。まず、プロジェクトには、静的ライブラリ (xcode 4.6 ios 6.x) であるサブ プロジェクトがあります。静的ライブラリは、イベントに従って独自のデリゲートを起動します。アプリは、静的ライブラリのデリゲート メソッドを実装します。実装では、以下を使用して UI 要素にアクセスし、他のイベントをトリガーします。Didgetnotified は、lib のデリゲート メソッドです。
- (void)didGetNotified
{
dispatch_async(dispatch_get_main_queue(), ^{
[self parseData];
NSNotificationCenter *notifyCenter = [NSNotificationCenter defaultCenter];
[notifyCenter addObserver:self
selector:@selector(updateUI)
name:@"updateUIN"
object:nil];
});
}
-(void) parseData {
//parse data and its ready now and send notification
[[NSNotificationCenter defaultCenter] postNotificationName:@"updateUIN" object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"updateUIN" object:nil];
}
-(void) updateUI {
//this method gets fired twice mostly
}
問題は、updateUI
が 2 回呼び出されることです。私は何が間違っているのかわかりません。それはスレッドで何かですか?静的 lib デリゲートはメイン スレッドにありません。しかし、私はメインスレッドでディスパッチを使用します。誰か説明してもらえますか?少し早いですがお礼を。