0

我想要UIAlertControllerUIAlertControllerStyleAlert样式,而使用UIAlertControllerStyleActionSheet样式解除UIAlertController样式。换句话说,我想在从动作表中点击一个选项后显示一个alertview。但是,没有alertview被呈现,则仅显示此消息日志中:在另一个UIAlertController原因中存在UIAlertController试图在释放视图控制器时加载视图控制器的视图是不允许的

尝试而它是 解除分配不允许加载视图控制器的视图,并且可以导致未定义的行为

这里我的代码:

UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"MyApp" message:@"Info" preferredStyle:UIAlertControllerStyleActionSheet]; 

    [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 

     // Cancel button tappped. 
     [self dismissViewControllerAnimated:YES completion:^{ 
     }]; 
    }]]; 

    [actionSheet addAction:[UIAlertAction actionWithTitle:@"Credits" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 

     UIAlertController * alert= [UIAlertController 
             alertControllerWithTitle:@"Credits" 
             message:@"Here some text in the alertview..." 
             preferredStyle:UIAlertControllerStyleAlert]; 

     UIAlertAction* yesButton = [UIAlertAction 
            actionWithTitle:@"Close" 
            style:UIAlertActionStyleDefault 
            handler:^(UIAlertAction * action) 
            { 
             //Handel your yes please button action here 


            }]; 

     [alert addAction:yesButton]; 

     [self dismissViewControllerAnimated:YES completion:^{ 
      // try to present the alertview 
      [self presentViewController:alert animated:YES completion:nil]; 
     }]; 
    }]]; 

    // Present action sheet. 
    [self presentViewController:actionSheet animated:YES completion:nil]; 

该操作表正在工作,而不是alertview。操作单从UITableViewController提供。非常感谢每一个帮助,在此先感谢

回答

1

固定..这里是代码。 您不需要关闭以加载AlertController。

UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"MyApp" message:@"Info" preferredStyle:UIAlertControllerStyleActionSheet]; 

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 

    // Cancel button tappped. 
    [self dismissViewControllerAnimated:YES completion:^{ 
    }]; 
}]]; 

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Credits" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 

    UIAlertController * alert= [UIAlertController 
            alertControllerWithTitle:@"Credits" 
            message:@"Here some text in the alertview..." 
            preferredStyle:UIAlertControllerStyleAlert]; 

    UIAlertAction* yesButton = [UIAlertAction 
           actionWithTitle:@"Close" 
           style:UIAlertActionStyleDefault 
           handler:^(UIAlertAction * action) 
           { 
            //Handel your yes please button action here 


           }]; 

    [alert addAction:yesButton]; 

    [self presentViewController:alert animated:YES completion:nil]; 
}]]; 

// Present action sheet. 
[self presentViewController:actionSheet animated:YES completion:nil]; 

只是去尝试一个空的项目通过添加代码 - (空)viewDidAppear:(BOOL)动画和正常工作。

希望帮助

+0

我犯了多么愚蠢的错误......谢谢!还要感谢@Mike Taverna – Kurtis92

2

问题是你的[自dismissViewControllerAnimated]完成区块内调用[自我presentViewController。

您试图呈现的警报视图控制器正在被释放,因为它是已被解散的自我视图控制器内的局部变量。

相关问题