2016-12-29 70 views
2

このメッセージを再度表示する必要があるかどうかを尋ねるアラートにチェックボックスを追加する必要があります。ボタンやテキストフィールドがコントローラに追加されたが、どこにでもチェックボックスが表示されなかったさまざまな例が出てきた。 UIAlertViewはバージョン9よりも非推奨ですので、私はそれを使いたくありません。UIAlertControllerのチェックボックスを追加してください

UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil message:@"Should I remind?" preferredStyle:UIAlertControllerStyleAlert]; 

UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { 
    [self goToAddReminderView]; 
}]; 
UIAlertAction *noAction = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) { 
[self.navigationController popViewControllerAnimated:YES]; 
}]; 

[alert addAction:yesAction]; 
[alert addAction:noAction]; 

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

私は例を挙げるでしょう。

+1

ネイティブではサポートされていません。 – hridayesh

答えて

6

iOSがネイティブサポートしていません。独自のカスタネットコントロールを作成する必要があります。

あなたが怒鳴るようなUIをカスタマイズする必要がhttps://www.cocoacontrols.com/controls/fcalertviewhttps://www.cocoacontrols.com/controls/cfalertviewcontroller

+0

CFAlertViewController(https://www.cocoacontrols.com/controls/cfalertviewcontroller)は非常に安定しており、他の多くの便利な機能をサポートしています。 –

+0

CFAlertViewControllerには現在のところメモリリークがあります。修正がマージされるのを待つ必要があり、新しいリリースです。 – Efren

1

で試すことができます。

私は単純な作業用コードスニペットを書いていますが、うまくいきます。

func showAlertController() 
    { 
     //simple alert dialog 
     let alertController = UIAlertController(title: "", message: "", preferredStyle: UIAlertControllerStyle.alert); 
     // Add Action 
     alertController.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.cancel, handler: nil)); 
     //show it 
     let btnImage = UIImage(named: "checkBoxImage")! 
     let imageButton : UIButton = UIButton(frame: CGRect(x: 0, y: 0, width: 50, height: 50)) 
     imageButton.setBackgroundImage(btnImage, for: UIControlState()) 
     imageButton.addTarget(self, action: #selector(ViewController.checkBoxAction(_:)), for: .touchUpInside) 
     alertController.view.addSubview(imageButton) 
     self.present(alertController, animated: false, completion: {() -> Void in 

      }) 
    } 


func checkBoxAction(_ sender: UIButton) 
{ 
    if sender.isSelected 
    { 
     sender.isSelected = false 
     let btnImage = UIImage(named: "checkBoxImage")! 
     sender.setBackgroundImage(btnImage, for: UIControlState()) 
    }else { 
     sender.isSelected = true 
     let btnImage = UIImage(named: "unCheckBoxImage")! 
     sender.setBackgroundImage(btnImage, for: UIControlState()) 
    } 
} 
関連する問題