我有一个奇怪的错误,我以编程方式创建了一个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
任何人都可以帮助我做错了吗?
提前致谢!
答案 0 :(得分:0)
试试这个
UIBarButtonItem *barButton = [[[UIBarButtonItem alloc]initWithImage:infoButton.currentImage style:UIBarButtonItemStyleBordered target:self action:@selector(showInfo:)] autorelease];
[self.navigationItem setLeftBarButtonItem:barButton];
谢谢:)
答案 1 :(得分:0)
我认为viewcontroller会被释放。您能否显示此viewcotroller的创建位置以及其视图在屏幕上的显示方式。
没有垃圾收集。不同之处可能是在调试设置中,对象会无限期地保留以便更好地记录