UIAlertView已經被棄用,iOS 8開始由UIAlertController取代它囉!如此變得更親切迷人~
過去能透過UIAlertView做出可填寫欄位UITextField,現在UIAlertController也能實現,而且更加方便好操作。
例如上圖程式碼這麼寫:
/** Theme: UIAlertController IDE: Xcode 7 Language: Objective C Date: 105/03/30 Author: HappyMan Blog: https://cg2010studio.wordpress.com/ */ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"修改暱稱" message:@"" preferredStyle:UIAlertControllerStyleAlert]; [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { // optionally configure the text field textField.keyboardType = UIKeyboardTypeDefault; }]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"送出" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { UITextField *textField = [alert.textFields firstObject]; }]; [alert addAction:okAction]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alert addAction:cancelAction]; [self presentViewController:alert animated:YES completion:nil];
看要增加幾個選項按鈕都可以,而且都是用Block來做後續處理,不用再像過去還要跳來跳去的Delegate。
隨意留個言吧:)~