設置通知時,可以設置不同的選擇器對其作出反應。但似乎沒有辦法通過選擇器刪除通知。例如:Objective-C:如何通過選擇器刪除通知?
// e.g. React to background notification by calling method 1
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(method1:) name:notification object:nil];
// e.g. React to background notification by calling method 2
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(method2:) name:notification object:nil];
現在,當通知觸發時,兩種方法都會對它做出反應。 如何選擇性刪除通知(例如,刪除通知處理程序method1)?
它看起來不像你可以,但沒有理由註冊兩種方法來首先在同一類上接收相同的通知。 – Droppy
我的理由是有理由的,因爲這兩個操作明顯不同。 – Boon
在這些條件下從'method1'調用'method2'。無論如何,您需要記住這些條件才能正確刪除通知。 – Droppy