在iOS 8后使用UIAlertController

来源:互联网 发布:sqlserver时间比较 编辑:程序博客网 时间:2024/06/05 20:54

创建实例

UIAlertController *alertController = [UIAlertControlleralertControllerWithTitle:@"标题"message:@"这个是UIAlertController的默认样式"preferredStyle:UIAlertControllerStyleAlert];

preferredStyle 选择类型


UIAlertControllerStyleActionSheet=0,

UIAlertControllerStyleAlert

UIAlertAction *cancelAction = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:nil];

UIAlertAction *okAction = [UIAlertActionactionWithTitle:@"好的"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *action) {

                [collectionView reloadItemsAtIndexPaths:@[indexPath]];

            }];

  [alertController addAction:cancelAction];

  [alertController addAction:okAction];


显示

[selfpresentViewController:alertControlleranimated:YEScompletion:nil];


文本对话框:

 [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField){

            textField.placeholder =@"登录";

        }];

        [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {

            textField.placeholder =@"密码";

            textField.secureTextEntry =YES;

        }];

        

        UIAlertAction *okAction = [UIAlertActionactionWithTitle:@"好的"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *action) {

            UITextField *login = alertController.textFields.firstObject;

            UITextField *password = alertController.textFields.lastObject;

            ...}]

好按钮可以读取文本窗中的值




1 0
原创粉丝点击