Question

in an iphone app I was displaying a simple UIActionSheet and it was working correctly on XCode 4.6 and now I want to migrate the app to XCode 5.

But when I moved to XCode 5, the app is crashing when showing the Action sheet.

I am using an iPhone 4 with ios 7 to test on both

This is my action sheet code (I removed most part of it to try to narrow down the issue)

UIActionSheet *languageMessage = [[UIActionSheet alloc] initWithTitle:@"title" delegate:nil cancelButtonTitle:@"cancel" destructiveButtonTitle:nil otherButtonTitles:nil];

languageMessage.actionSheetStyle=UIActionSheetStyleBlackTranslucent;
[languageMessage showInView:self.view]; 

The app is crashing (SIGABRT) on this line

[languageMessage showInView:self.view]; 

while debugging self.view is not null and is read correctly so that is not the issue

This is the stack trace

* 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

What might be causing the crash on XCode 5 and not on XCode 4.6

Thank you very much for any help.

Was it helpful?

Solution

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

You seem to be creating and showing UIActionSheet in viewDidLoad method where the view is completely created. There is a fair chance that the view referred through self.view is not completely created.

You should move the showLanguageSheet call to viewDidAppear method instead. If you want to display the action sheet only once when view controller get created/displayed then hold a simple BOOL flag and set it after displaying action sheet.

Something like,

-(void) viewDidAppear {
    if(!isActionSheetShown) {
        [self showLanguageSheet];
        isActionSheetShown = YES;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top