Luciano Nascimento Luciano Nascimento - 6 months ago 190
Objective-C Question

Strange dismissViewControllerAnimated Crash - iOS 8

My app is crashing, only in iOS 8.4, when I try to

dismissViewControllerAnimated:NO
, just after an alert with an
UITextField
.

Changing to animated
YES
it's working well, but I guess that's the not properly fix.




Code: (
UIModalPresentationCurrentContext
Modal)

- (IBAction)openAlertWithTextField:(id)sender
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Type a number:" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Confirm", nil];
[alert setAlertViewStyle:UIAlertViewStylePlainTextInput];
UITextField * alertTextField = [alert textFieldAtIndex:0];
[alertTextField setKeyboardType:UIKeyboardTypeNumberPad];
[alertTextField setDelegate:self];
[alert show];
}

#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
// Crash
[self dismissViewControllerAnimated:NO completion:nil];

// No Crash
[self dismissViewControllerAnimated:YES completion:nil];
}
}





Crash Log:

Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000010

Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x1981c7bd0 objc_msgSend + 16
1 UIKit 0x18b29c9dc -[UITextField _shouldEndEditing] + 84
2 UIKit 0x18b21ac70 -[UIResponder resignFirstResponder] + 84
3 UIKit 0x18b29c8bc -[UITextField resignFirstResponder] + 124
4 UIKit 0x18b29395c -[UIView(Hierarchy) _removeFirstResponderFromSubtree] + 208
5 UIKit 0x18b43effc __UIViewWillBeRemovedFromSuperview + 96
6 UIKit 0x18b16ac48 -[UIView(Hierarchy) removeFromSuperview] + 108
7 UIKit 0x18b47a94c __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke504 + 364
8 UIKit 0x18b476784 -[UIPresentationController transitionDidFinish:] + 112
9 UIKit 0x18b4790c0 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 168
10 UIKit 0x18b292f64 -[_UIViewControllerTransitionContext completeTransition:] + 132
11 UIKit 0x18b1a8708 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 408
12 UIKit 0x18b1a8270 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 188
13 UIKit 0x18b1a8178 -[UIViewAnimationState animationDidStop:finished:] + 104
14 QuartzCore 0x18aab162c CA::Layer::run_animation_callbacks(void*) + 296
15 libdispatch.dylib 0x198831954 _dispatch_client_callout + 16
16 libdispatch.dylib 0x19883620c _dispatch_main_queue_callback_4CF + 1608
17 CoreFoundation 0x1866af7f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
18 CoreFoundation 0x1866ad8a0 __CFRunLoopRun + 1492
19 CoreFoundation 0x1865d92d4 CFRunLoopRunSpecific + 396
20 GraphicsServices 0x18feef6fc GSEventRunModal + 168
21 UIKit 0x18b1d6f40 UIApplicationMain + 1488
22 Get In Manager 0x10006320c main (main.m:16)
23 libdyld.dylib 0x19885ea08 start + 4


Zoombie:

2016-05-25 03:02:26.699 App[75590:5686413] *** -[MyUIViewController respondsToSelector:]: message sent to deallocated instance 0x7ff1a2f7a7f0

Answer

Maybe you are doing it too early and should try doing in this:

- alertView:didDismissWithButtonIndex:
Comments