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。

您試圖呈現的警報視圖控制器正在被釋放,因爲它是已被解散的自我視圖控制器內的局部變量。

相關問題