mad*_*max 6 cocoa-touch exc-bad-access nsnotification ipad
我对NSNotification对象有一种奇怪的行为.
我的应用程序有一个导航控制器,第一个视图是一个表视图,第二个视图只是一个显示所选单元格数据的视图控制器.
所以在这个数据视图控制器中,当我按下按钮时,我发送通知.该通知最初也有效.
但是当我回到表视图,并再次推栈中的数据视图控制器,并通知触摸按钮,整个应用程序没有错误日志崩溃.
Xcode只突出显示这一行:
[[NSNotificationCenter defaultCenter]
postNotificationName:@"toggleNoteView" object:nil];
Run Code Online (Sandbox Code Playgroud)
我发送通知的功能:
- (IBAction) toggleNoteView: (id) sender
{
[[NSNotificationCenter defaultCenter]
postNotificationName:@"toggleNoteView" object:nil];
}
Run Code Online (Sandbox Code Playgroud)
这是接收者:
- (id)init {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(toggleNoteView:)
name:@"toggleNoteView" object:nil];
...
}
- (void) toggleNoteView:(NSNotification *)notif {
takingNotes = !takingNotes;
}
Run Code Online (Sandbox Code Playgroud)
编辑:现在我确实得到了一些错误日志.
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
Run Code Online (Sandbox Code Playgroud)
卸载视图时不要忘记删除观察者.基本上发生的事情是,当您向不存在的视图发布通知时,它无法运行选择器,从而导致应用程序崩溃.
-(void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1452 次 |
| 最近记录: |