我有一个奇怪的错误,我以编程方式创建了一个 UIBarButtonItem,当它连接到 Xcode 时,它在模拟器和设备上都可以正常工作。但是每当我拔下设备时,当我触摸按钮时应用程序就会崩溃。
这是我创建按钮并将其分配给导航栏的方法:
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(backToMainPage:)];
方法:
- (void)backToMainPage:(id)sender
{
NSLog(@"...");
}
这是我得到的错误:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x40290020
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x3693d386 _ZL12realizeClassP7class_t + 34
1 libobjc.A.dylib 0x3693d3e6 _ZL12realizeClassP7class_t + 130
2 libobjc.A.dylib 0x36937836 prepareForMethodLookup + 74
3 libobjc.A.dylib 0x36937740 lookUpMethod + 40
4 libobjc.A.dylib 0x3693770c _class_lookupMethodAndLoadCache3 + 12
5 libobjc.A.dylib 0x36936fc4 objc_msgSend_uncached + 20
6 UIKit 0x30f28fa8 -[UIApplication sendAction:to:from:forEvent:] + 56
7 UIKit 0x30f28f64 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 24
8 UIKit 0x30f28f42 -[UIControl sendAction:to:forEvent:] + 38
9 UIKit 0x30f28cb2 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 486
10 UIKit 0x30f295ea -[UIControl touchesEnded:withEvent:] + 470
11 UIKit 0x30f27acc -[UIWindow _sendTouchesForEvent:] + 312
12 UIKit 0x30f274ba -[UIWindow sendEvent:] + 374
13 UIKit 0x30f0d836 -[UIApplication sendEvent:] + 350
14 UIKit 0x30f0d0dc _UIApplicationHandleEvent + 5820
15 GraphicsServices 0x33f30224 PurpleEventCallback + 876
16 CoreFoundation 0x3494251c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32
17 CoreFoundation 0x349424be __CFRunLoopDoSource1 + 134
18 CoreFoundation 0x3494130c __CFRunLoopRun + 1364
19 CoreFoundation 0x348c449e CFRunLoopRunSpecific + 294
20 CoreFoundation 0x348c4366 CFRunLoopRunInMode + 98
21 GraphicsServices 0x33f2f432 GSEventRunModal + 130
22 UIKit 0x30f3be76 UIApplicationMain + 1074
谁能帮我我做错了什么?
提前致谢!