我對NSNotification對象有一個奇怪的行爲。
我的應用程序有一個導航控制器,第一個視圖是一個表視圖,第二個視圖只是一個視圖控制器,顯示所選單元格的數據。
所以在這個數據視圖控制器中,當我按下一個按鈕時,我發送一個通知。 該通知也起作用。NSNotification導致分段錯誤
但是,當我回到表視圖,並再次推動數據視圖控制器在堆棧上,並與通知觸摸按鈕,整個應用程序崩潰,沒有錯誤日誌。
Xcode中只強調了這一行:
[[NSNotificationCenter defaultCenter]
postNotificationName:@"toggleNoteView" object:nil];
,我發送了通知功能:
- (IBAction) toggleNoteView: (id) sender
{
[[NSNotificationCenter defaultCenter]
postNotificationName:@"toggleNoteView" object:nil];
}
這是接收器:
- (id)init {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(toggleNoteView:)
name:@"toggleNoteView" object:nil];
...
}
- (void) toggleNoteView:(NSNotification *)notif {
takingNotes = !takingNotes;
}
編輯:現在我沒有得到一些錯誤日誌。
2011-06-27 23:05:05.957 L3T[3228:707] -[UINavigationItemView toggleNoteView:]: unrecognized selector sent to instance 0x4b235f0
2011-06-27 23:05:06.075 L3T[3228:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationItemView toggleNoteView:]: unrecognized selector sent to instance 0x4b235f0'
*** Call stack at first throw:
(
0 CoreFoundation 0x3634f64f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x370a2c5d objc_exception_throw + 24
2 CoreFoundation 0x363531bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
3 CoreFoundation 0x36352649 ___forwarding___ + 508
4 CoreFoundation 0x362c9180 _CF_forwarding_prep_0 + 48
5 Foundation 0x35c45183 _nsnote_callback + 142
6 CoreFoundation 0x3631e20f __CFXNotificationPost_old + 402
7 CoreFoundation 0x362b8eeb _CFXNotificationPostNotification + 118
8 Foundation 0x35c425d3 -[NSNotificationCenter postNotificationName:object:userInfo:] + 70
9 Foundation 0x35c441c1 -[NSNotificationCenter postNotificationName:object:] + 24
10 L3T 0x0003d17f -[Container toggleNoteView:] + 338
11 CoreFoundation 0x362bf571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24