2011-06-24 11 views
2

は、私は2 NSNotificationsのクラスが目的C:1つのクラスに2つのNSNotificationを設定する際に問題がありますか?

//Set up notifications 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(getData) 
               name:@"Answer Submitted" 
               object:nil]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(reloadTable) 
               name:@"Comment Submitted" 
               object:nil]; 

を実装している私はちょうど単一のクラスで2人のオブザーバーを設定しても大丈夫であるかどうかを確認したいと思いますか?また、オブザーバを削除するときに、deallocメソッドでオブザーバを1つだけ削除します。それは問題ですか?

答えて

4

1つのクラスに複数のオブザーバを置くことはまったく問題ありません。オブザーバーが終了したら、オブザーバーを登録解除する必要があります。

Objective-Cのオブザーバーパターンの詳細はhereです。