UIAlertController 警告框
2015-10-28 20:48
357 查看
switch (button.tag) {
case 101:
{
/*
按钮的类型
UIAlertActionStyleDefault = 0,
UIAlertActionStyleCancel,
UIAlertActionStyleDestructive
*/
//弹出警告框UIAlertControllerStyleAlert
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"非法入侵" preferredStyle:UIAlertControllerStyleAlert];
//增加 按钮 行为
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
//这个block 点击取消按钮 会 回调的 代码块
NSLog(@"alert 取消被点击");
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"alert 确定被点击");
}]];
//只能模态跳转
[self presentViewController:alert animated:YES completion:nil];
}
break;
case 102:
{
//UIAlertControllerStyleActionSheet
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"分享" message:@"看这里。。。" preferredStyle:UIAlertControllerStyleActionSheet];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"QQ" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"QQ被点击");
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"人人" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"人人被点击");
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"sina" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"sina被点击");
}]];
//取消
[actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"取消");
}]];
//删除
[actionSheet addAction:[UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
NSLog(@"删除被点击");
}]];
//模态跳转
[self presentViewController:actionSheet animated:YES completion:nil];
}
break;
case 103:
{
//alert 自带 textField
UIAlertController *alertText = [UIAlertController alertControllerWithTitle:@"登录" message:@"登录账号" preferredStyle:UIAlertControllerStyleAlert];
//增加textField
[alertText addTextFieldWithConfigurationHandler:^(UITextField *textField) {
//这个block 初始化 alert的时候回调 可以对textField进行设置
textField.placeholder = @"请输入用户名";
}];
[alertText addTextFieldWithConfigurationHandler:^(UITextField *textField) {
//这个block 初始化 alert的时候回调 可以对textField进行设置
textField.placeholder = @"请输入密码";
textField.secureTextEntry = YES;
}];
//增加按钮
[alertText addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"取消被点击");
}]];
[alertText addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//打印 textField的内容
//alertText.textFields获取 textfield数组
NSLog(@"name:%@",[alertText.textFields[0] text]);
NSLog(@"passwd:%@",[alertText.textFields[1] text]);
}]];
[self presentViewController:alertText animated:YES completion:nil];
}
break;
case 101:
{
/*
按钮的类型
UIAlertActionStyleDefault = 0,
UIAlertActionStyleCancel,
UIAlertActionStyleDestructive
*/
//弹出警告框UIAlertControllerStyleAlert
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"非法入侵" preferredStyle:UIAlertControllerStyleAlert];
//增加 按钮 行为
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
//这个block 点击取消按钮 会 回调的 代码块
NSLog(@"alert 取消被点击");
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"alert 确定被点击");
}]];
//只能模态跳转
[self presentViewController:alert animated:YES completion:nil];
}
break;
case 102:
{
//UIAlertControllerStyleActionSheet
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"分享" message:@"看这里。。。" preferredStyle:UIAlertControllerStyleActionSheet];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"QQ" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"QQ被点击");
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"人人" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"人人被点击");
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"sina" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"sina被点击");
}]];
//取消
[actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"取消");
}]];
//删除
[actionSheet addAction:[UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
NSLog(@"删除被点击");
}]];
//模态跳转
[self presentViewController:actionSheet animated:YES completion:nil];
}
break;
case 103:
{
//alert 自带 textField
UIAlertController *alertText = [UIAlertController alertControllerWithTitle:@"登录" message:@"登录账号" preferredStyle:UIAlertControllerStyleAlert];
//增加textField
[alertText addTextFieldWithConfigurationHandler:^(UITextField *textField) {
//这个block 初始化 alert的时候回调 可以对textField进行设置
textField.placeholder = @"请输入用户名";
}];
[alertText addTextFieldWithConfigurationHandler:^(UITextField *textField) {
//这个block 初始化 alert的时候回调 可以对textField进行设置
textField.placeholder = @"请输入密码";
textField.secureTextEntry = YES;
}];
//增加按钮
[alertText addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"取消被点击");
}]];
[alertText addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//打印 textField的内容
//alertText.textFields获取 textfield数组
NSLog(@"name:%@",[alertText.textFields[0] text]);
NSLog(@"passwd:%@",[alertText.textFields[1] text]);
}]];
[self presentViewController:alertText animated:YES completion:nil];
}
break;
相关文章推荐
- 浅析UITableViewCell重用机制
- java Vamei快速教程20 GUI
- UVA——10534 Wavio Sequence
- poj 1458 Common Subsequence (最长公共子序列)
- iOS开发UI篇—CAlayer层的属性(一)
- 对QT namespace UI的理解
- jira插件带ui界面和几种方式
- UISlider滑条
- UISearchController
- UITextView
- UIDatePicker
- E - Subsequence
- uestc 1222 Sudoku
- IOS UITableView的分隔线多出问题
- easyUi datebox 默认当天
- UIAlertController replaces the UIActionSheet and UIAlertView
- cordys static value 和 read from message
- UIAlertView is deprecated in iOS 8.
- Cannot reload AVD List : Value '280dpi' is not facet-valid with ......---Android studio调试错误
- Frequently Asked Questions - P-thresholds