我对 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