以下の内容はhttps://anton0825.hatenablog.com/entry/20120704/1343375530より取得しました。


– addObserverForName:object:queue:usingBlock:で登録したObserverが削除できない

以下のコードで削除しようとしていたが、ブロックを使った場合はこれでは削除できない。

[[NSNotificationCenter defaultCenter] removeObserver:self];

以下のようにObserverを登録するときの返値をインスタンス変数に持っておいて、それをremoveObserverに渡さないといけない。

    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    self.observer = [center addObserverForName:CHANGE_STOCK_PRICE_NOTIFICATION object:nil queue:nil usingBlock:^(NSNotification *notification){
        ・・・
    }];
[[NSNotificationCenter defaultCenter] removeObserver:self.observer];

これは使いにくいなぁ。。まあブロック使わない場合よりは読みやすいのでブロック使うけど。




以上の内容はhttps://anton0825.hatenablog.com/entry/20120704/1343375530より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14