iOS - 提示信息 - UIAlertView、UIActionSheet、UIAlertController的实际应用

1、UIAlertView(屏幕*弹出框)(不需要服从代理)

UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"done", nil];

//设置alertView的样式

alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;

//使alertView展示出来

[alertView show];

//延迟5秒执行dismissAlertView

[self performSelector:@selector(dismissAlertView:) withObject:alertView afterDelay:5];

// alertview消失的方法

-(void)dismissAlertView:(UIAlertView*)alert{

[alert dismissWithClickedButtonIndex:0 animated:YES];

}

//点击alertView button 触发的方法。

//buttonIndex按钮的索引值 cancel的index为0

//(代理方法)

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

//获取alertview上的输入文本

UITextField * textField1 = [alertView textFieldAtIndex:0];

NSLog(@"%@",textField1.text);

2、UIActionSheet(屏幕底端出现)

UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"题目" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"可以", nil];

//destructiveButtonTitle 红色字体

//使sheet显示出来

[sheet showInView:self.view];

//延迟5秒执行dismissAlertView

[self performSelector:@selector(dismissActionSheet:) withObject:sheet afterDelay:5];

// sheet 消失的方法

[sheet dismissWithClickedButtonIndex:0 animated:YES];

//代理方法(index顺序从上到下)

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

switch (buttonIndex) {

case 0:

NSLog(@"确定");

break;

case 1:

NSLog(@"可以");

break;

case 2:

NSLog(@"取消");

break;

default:

break;

}

}

3、UIAlertController

//创建UIAlertController

UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"题目" message:@"消息" preferredStyle:UIAlertControllerStyleAlert];

//创建按钮

UIAlertAction * action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *  action) {

NSLog(@"no");

}];

UIAlertAction * action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) {

NSLog(@"ok");

UITextField * field = alertController.textFields[0];

NSLog(@"%@",field.text);

}];

//添加文本

[alertController addTextFieldWithConfigurationHandler:^(UITextField * textField) {

textField.secureTextEntry = YES;

}];

[alertController addAction:action1];

[alertController addAction:action2];

//展示alertController

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

上一篇:如何抓取电商的数据 & Python


下一篇:wcf,jquery,post,跨域