Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我在iOS8中使用了uialertview,但在我两次单击取消按钮后应用程序崩溃_Ios_Crash_Uialertview - Fatal编程技术网

我在iOS8中使用了uialertview,但在我两次单击取消按钮后应用程序崩溃

我在iOS8中使用了uialertview,但在我两次单击取消按钮后应用程序崩溃,ios,crash,uialertview,Ios,Crash,Uialertview,我在cancel delegate方法中不执行任何操作。 我需要帮助 我的代码: - (void)back{ if(_stateView.stateType == StateType_Failed || _stateView.stateType == StateType_WiFi){ UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:[NSString stringWithFormat:

我在cancel delegate方法中不执行任何操作。 我需要帮助

我的代码:

- (void)back{
if(_stateView.stateType == StateType_Failed || _stateView.stateType == StateType_WiFi){
    UIAlertView *alertView =  [[UIAlertView alloc]initWithTitle:@"温馨提示" message:[NSString stringWithFormat:@"您确认要放弃连接 %@ 免费热点",_SSID] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"不,谢谢", nil];
    [alertView show];
    return;
}
[self.navigationController popViewControllerAnimated:YES];
}

}

我添加了一个断点,得到了崩溃日志和堆栈

[_UIAlertControllerShimPresenterWindow becomeFirstResponder]: message sent to deallocated instance 0x15e752ec0

(lldb) bt

* thread #1: tid = 0x1c8de, 0x000000018359017c CoreFoundation`___forwarding___ + 968, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=1, subcode=0x18359017c)
  * frame #0: 0x000000018359017c CoreFoundation`___forwarding___ + 968
    frame #1: 0x0000000183492ccc CoreFoundation`_CF_forwarding_prep_0 + 92
    frame #2: 0x00000001880ac704 UIKit`-[UIPeripheralHost(UIKitInternal) _restoreInputViewsWithId:animated:] + 356
    frame #3: 0x00000001883ac834 UIKit`-[UIAlertController _restoreInputViewsAnimated:] + 128
    frame #4: 0x00000001883ac5e0 UIKit`-[UIAlertController viewDidDisappear:] + 92
    frame #5: 0x0000000187fe3f28 UIKit`-[UIViewController _setViewAppearState:isAnimating:] + 440
    frame #6: 0x0000000187fe452c UIKit`-[UIViewController _endAppearanceTransition:] + 344
    frame #7: 0x00000001882d2b58 UIKit`-[UIPresentationController transitionDidFinish:] + 984
    frame #8: 0x00000001882d512c UIKit`__56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 168
    frame #9: 0x00000001880eefd0 UIKit`-[_UIViewControllerTransitionContext completeTransition:] + 132
    frame #10: 0x0000000188004774 UIKit`-[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 408
。。。。。。
(代码太多了,我不能全部发布。)

在抛出时添加一个异常断点,并在调试时尝试重新生成它。在这里发布一些代码,让我们看看有什么问题


您的UIAlertControllersImpersenterWindow似乎被解除分配得太早了…

在显示警报之前,您正在弹出viewcontroller

删除
[self.navigationController popViewControllerAnimated:YES]
-(void)back
方法

为了清楚起见。您的代码应该是:

-(void)back
{
     if(_stateView.stateType == StateType_Failed || _stateView.stateType == StateType_WiFi)
    { 
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:[NSString stringWithFormat:@"您确认要放弃连接 %@ 免费热点",_SSID] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"不,谢谢", nil];
    [alertView show]; 
    return; 
    } 
    }

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{ 
if(buttonIndex == 0)
{ 
[self.navigationController popViewControllerAnimated:YES]; 
} 
}

请在这里发布您的代码,显示alertview和ClickedButtonIndex:(NSInteger)buttonIndex方法我做到了,您能帮助我吗?谢谢。您如何能够单击取消按钮两次,第一次单击本身alertview应该被取消。是的,实际上我单击了第一次,它被取消了。然后我点击后退按钮,它显示。所以我可以点击它两次,然后它崩溃了。但在这种情况下,它应该弹出你的ViewController。对吗?或者功能是什么。我这样做了,这样我就可以得到这个日志,并且我已经发布了我的代码,谢谢。不要这样做,如果条件返回存在,当显示AlertView时,这将不会让控件传递给popViewControllerAnimated。
-(void)back
{
     if(_stateView.stateType == StateType_Failed || _stateView.stateType == StateType_WiFi)
    { 
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:[NSString stringWithFormat:@"您确认要放弃连接 %@ 免费热点",_SSID] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"不,谢谢", nil];
    [alertView show]; 
    return; 
    } 
    }

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{ 
if(buttonIndex == 0)
{ 
[self.navigationController popViewControllerAnimated:YES]; 
} 
}