我的应用程序崩溃,仅在iOS 8.4中,当我尝试使用dismissViewControllerAnimated:NO
的{{1}}之后尝试UITextField
时。
更改为动画YES
它运行良好,但我猜这是不正确的修复。
代码:(UIModalPresentationCurrentContext
模态)
- (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];
}
}
崩溃日志:
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
答案 0 :(得分:1)
你做得太早,应该尝试这样做:
- alertView:didDismissWithButtonIndex:
答案 1 :(得分:0)
您正在使用UIAlertview,任何按钮点击自动关闭视图。
你并没有忽视回忆UIAlertview方法的观点。例如:
[alertview show];