亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

IOS開發(fā) UIAlertController詳解及實例代碼

 更新時間:2016年12月23日 11:48:39   投稿:lqh  
這篇文章主要介紹了 IOS開發(fā) UIAlertController詳解及實例代碼的相關(guān)資料,需要的朋友可以參考下

 IOS開發(fā) UIAlertController詳解

在iOS 8.0后,蘋果棄用了UIAlertView和UIActionSheet,轉(zhuǎn)而使用UIAlertController把之前的UIAlertView和UIActionSheet整合在一起。新版的API變得簡潔了不少幾行代碼就可實現(xiàn)之前一大片代碼的功能

 UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert"
                                  message:@"This is an alert."
                              preferredStyle:UIAlertControllerStyleAlert];

  UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
                             handler:^(UIAlertAction * action) {
                               NSLog(@"你好你好");
                             }];

  UIAlertAction* defaultAction2 = [UIAlertAction actionWithTitle:@"OK2" style:UIAlertActionStyleDefault
                             handler:^(UIAlertAction * action) {
                               NSLog(@"你好你好");
                             }];

  [alert addAction:defaultAction];
  [alert addAction:defaultAction2];
  [self presentViewController:alert animated:YES completion:nil];

初始化AlertView沒有太大區(qū)別,主要區(qū)別就是添加事件。蘋果公司新添加了UIAlertAction專門用來添加事件。一個Action對應(yīng)一個事件,添加到alert上就可以使用。

切換為ActionSheet只需要修改preferredStyle為UIAlertControllerStyleActionSheet

也可以添加輸入框代碼如下

  [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
    textField.placeholder = @"輸入用戶名";
  }];



感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論