1. 程式人生 > >提示框新增輸入框的問題

提示框新增輸入框的問題

在開發中我們經常會遇到要提示使用者資訊的地方,這是就用到了AlertView了。但是在ios8以後AlertView就不在是被棄用了變成了一個控制器了AlertViewController,使用方法也有點發生變化,下面是太輸入框的提示框的程式碼示例

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"請輸入場景名稱" message:@"輸出" preferredStyle:UIAlertControllerStyleAlert];

    //新增的輸入框
    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        // 可以在這裡對textfield進行定製,例如改變背景色
//textField.backgroundColor = [UIColor orangeColor]; }]; UIAlertAction *Action = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; UIAlertAction *twoAc = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { //新增的帶輸入框的提示框
_senceText = (UITextField *)alert.textFields.firstObject; }]; [alert addAction:Action]; [alert addAction:twoAc]; [self presentViewController:alert animated:YES completion:nil]; }