-
遭遇crash
一開始我也沒有想到[NSNotificationCenter postNotificationName:object:]這個(gè)人畜無害的系統(tǒng)函數(shù)帶來莫名其妙的閃退。所以在查代碼之初,我壓根就沒有懷疑過它购城。
截張圖 原因
說起來原因就是對(duì)于通知中心的錯(cuò)誤使用,監(jiān)聽postName的觀察者沒有remove匣沼。詳情請(qǐng)看學(xué)習(xí)
- (void)postNotificationName:(NSNotificationName)aName object:(NSString *)anObject; notificationName Name of the notification to post. Must not be nil. notificationSender Sender of the notification. May be nil.
通知中心在添加觀察者時(shí)使用了unsafe_unretained,這篇文章作了詳細(xì)的介紹捂龄。
通知中心在發(fā)通知的時(shí)候做的事情大致如下:
- 收到指定* notificationName*的消息释涛,
- 檢查有沒有這個(gè)消息的觀察者,
- 給觀察者發(fā)消息