2013-04-26 63 views
0

說,如果我有幾個:NSNotificationCenter:removeAllObserver for self works for several observing objects?

[[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(notificationReceived:) 
               name:NotificationA 
               object:self.player]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(notificationReceived:) 
               name:NotificationB 
               object:self.player]; 

的對象是所有self.player但對於不同的通知,我到底做:

[[NSNotificationCenter defaultCenter] removeObserver:self]; 

這是罰款,我必須使用完整的方法刪除每個通知的觀察者?目前我在視圖控制器卸載時遇到問題,但player仍在後臺播放。

感謝

+0

你在哪裏調用'removeObserver',我的意思是在哪種方法? – 2013-04-26 05:49:51

+0

@Deepesh嗨,我叫它在viewDidUnload和viewWillDisappear – hzxu 2013-04-26 06:32:51

+0

你的代碼似乎好,它應該工作。 viewDidUnload在IOS6中被棄用,但是你在'viewWillDisappear'中使用'removeObserver',所以我沒有看到你的代碼有任何問題。 – 2013-04-26 06:56:44

回答

2

docs說:「removeObserver:刪除所有指定從接收的調度表定的觀察者的條目。」所以你的方法調用就足夠了。