在iphone应用程序中我显示了一个简单的UIActionSheet,它在XCode 4.6上运行正常,现在我想将应用程序迁移到XCode 5。
但是当我搬到XCode 5时,应用程序在显示Action表时崩溃了。
我正在使用带有ios 7的iPhone 4进行测试
这是我的行动表代码(我删除了大部分内容以尝试缩小问题范围)
UIActionSheet *languageMessage = [[UIActionSheet alloc] initWithTitle:@"title" delegate:nil cancelButtonTitle:@"cancel" destructiveButtonTitle:nil otherButtonTitles:nil];
languageMessage.actionSheetStyle=UIActionSheetStyleBlackTranslucent;
[languageMessage showInView:self.view];
应用程序在此行崩溃( SIGABRT )
[languageMessage showInView:self.view];
虽然调试self.view
不为空并且已正确读取,因此不是问题
这是堆栈跟踪
* thread #1: tid = 0x19cd1e, 0x3860f688 libobjc.A.dylib`objc_exception_throw, queue = 'com.apple.main-thread, stop reason = breakpoint 35.1
frame #0: 0x3860f688 libobjc.A.dylib`objc_exception_throw
frame #1: 0x30bd8bc6 UIKit`-[UIActionSheet _assertIfValidForView:] + 190
frame #2: 0x30c403b4 UIKit`-[UIActionSheet showInView:] + 164
frame #3: 0x00126cac Bassara`-[RootLoginViewController showLanguageSheet](self=0x165ba810, _cmd=0x00371c48) + 444 at RootLoginViewController.m:84
frame #4: 0x00126ac6 Bassara`-[RootLoginViewController viewDidLoad](self=0x165ba810, _cmd=0x30ffef84) + 774 at RootLoginViewController.m:68
frame #5: 0x309f737a UIKit`-[UIViewController loadViewIfRequired] + 518
frame #6: 0x309f7138 UIKit`-[UIViewController view] + 24
frame #7: 0x309fde04 UIKit`-[UIWindow addRootViewControllerViewIfPossible] + 64
frame #8: 0x309fb4da UIKit`-[UIWindow _setHidden:forced:] + 306
frame #9: 0x30a6608c UIKit`-[UIWindow makeKeyAndVisible] + 60
frame #10: 0x30a62e58 UIKit`-[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1656
frame #11: 0x30a5d352 UIKit`-[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 714
frame #12: 0x309f841e UIKit`-[UIApplication handleEvent:withNewEvent:] + 3130
frame #13: 0x309f7720 UIKit`-[UIApplication sendEvent:] + 72
frame #14: 0x30a5cb3c UIKit`_UIApplicationHandleEvent + 664
frame #15: 0x32e9370c GraphicsServices`_PurpleEventCallback + 608
frame #16: 0x32e932f6 GraphicsServices`PurpleEventCallback + 34
frame #17: 0x2e24a9de CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
frame #18: 0x2e24a97a CoreFoundation`__CFRunLoopDoSource1 + 346
frame #19: 0x2e24914e CoreFoundation`__CFRunLoopRun + 1398
frame #20: 0x2e1b3c26 CoreFoundation`CFRunLoopRunSpecific + 522
frame #21: 0x2e1b3a0a CoreFoundation`CFRunLoopRunInMode + 106
frame #22: 0x30a5bdd8 UIKit`-[UIApplication _run] + 760
frame #23: 0x30a57048 UIKit`UIApplicationMain + 1136
frame #24: 0x00044e80 Bassara`main(argc=1, argv=0x27dc3cf4) + 116 at main.m:16
thread #2: tid = 0x19cd41, 0x38bbb83c libsystem_kernel.dylib`kevent64 + 24, queue = 'com.apple.libdispatch-manager
frame #0: 0x38bbb83c libsystem_kernel.dylib`kevent64 + 24
frame #1: 0x38b06e0c libdispatch.dylib`_dispatch_mgr_invoke + 232
frame #2: 0x38af63a2 libdispatch.dylib`_dispatch_mgr_thread$VARIANT$up + 38
thread #3: tid = 0x19cd43, 0x38bcec7c libsystem_kernel.dylib`__workq_kernreturn + 8
frame #0: 0x38bcec7c libsystem_kernel.dylib`__workq_kernreturn + 8
frame #1: 0x38c34dca libsystem_pthread.dylib`_pthread_wqthread + 310
frame #2: 0x38c34c84 libsystem_pthread.dylib`start_wqthread + 8
thread #4: tid = 0x19cd48, 0x38bcec7c libsystem_kernel.dylib`__workq_kernreturn + 8
frame #0: 0x38bcec7c libsystem_kernel.dylib`__workq_kernreturn + 8
frame #1: 0x38c34dca libsystem_pthread.dylib`_pthread_wqthread + 310
thread #5: tid = 0x19cd5c, 0x38bcec7c libsystem_kernel.dylib`__workq_kernreturn + 8
frame #0: 0x38bcec7c libsystem_kernel.dylib`__workq_kernreturn + 8
frame #1: 0x38c34dca libsystem_pthread.dylib`_pthread_wqthread + 310
可能导致XCode 5崩溃而非XCode 4.6崩溃的原因
非常感谢您的帮助。
答案 0 :(得分:1)
frame #3: 0x00126cac Bassara`-[RootLoginViewController showLanguageSheet](self=0x165ba810, _cmd=0x00371c48) + 444 at RootLoginViewController.m:84
frame #4: 0x00126ac6 Bassara`-[RootLoginViewController viewDidLoad](self=0x165ba810, _cmd=0x30ffef84) + 774 at RootLoginViewController.m:68
您似乎在UIActionSheet
方法中创建并显示viewDidLoad
,其中视图已完全创建。通过view
引用的self.view
很可能没有完全创建。
您应该将showLanguageSheet
来电转移到viewDidAppear
方法。如果要在创建/显示视图控制器时仅显示一次操作表,则保持一个简单的BOOL
标志并在显示操作表后进行设置。
类似的东西,
-(void) viewDidAppear {
if(!isActionSheetShown) {
[self showLanguageSheet];
isActionSheetShown = YES;
}
}