UIAlertController UIAlertAction (UIAlertView, UIActionSheet)
来源:互联网 发布:动物知乎 编辑:程序博客网 时间:2024/05/07 01:25
- (void)viewDidLoad {
[superviewDidLoad];
NSArray * items = @[@"课程",@"机构"];
jobAndCompanySegment = [[UISegmentedControlalloc] initWithItems:items];
jobAndCompanySegment.frame =CGRectMake(320/4,100,480/2,40);
jobAndCompanySegment.tintColor = [UIColororangeColor];
[jobAndCompanySegmentaddTarget:selfaction:@selector(segChanged:)forControlEvents:UIControlEventValueChanged];
jobAndCompanySegment.selectedSegmentIndex =0;
[self.viewaddSubview:jobAndCompanySegment];
}
- (void)segChanged:(UISegmentedControl *)sender
{
// 1. 创建UIAlertControl变量,但并不穿GIAn
UIAlertController *alertController = nil;
// 2. 根据点击的item创建不同样式的alertController
switch (sender.selectedSegmentIndex) {
case0: { // 弹出AlertView
alertController = [UIAlertControlleralertControllerWithTitle:@"Title"message:@"Message"preferredStyle:UIAlertControllerStyleAlert];
break;
}
case1: { // 弹出ActionSheet
alertController = [UIAlertControlleralertControllerWithTitle:@"Title"message:@"Message"preferredStyle:UIAlertControllerStyleActionSheet];
break;
}
default:
break;
}
// 3. 添加取消按钮
// 3.1 UIAlertAction 表示一个按钮,同时,这个按钮带有处理事件的block
UIAlertAction *action = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:^(UIAlertAction *action) {
NSLog(@"取消");
}];
// 3.2 添加到alertController上
[alertController addAction:action];
// 4. 添加需要谨慎操作的按钮,文字默认是红色的
[alertController addAction:({
UIAlertAction *action = [UIAlertActionactionWithTitle:@"谨慎操作的按钮"style:UIAlertActionStyleDestructivehandler:^(UIAlertAction *action) {
NSLog(@"谨慎操作的按钮");
}];
action;
})];
// 5. 添加确定按钮
[alertController addAction:({
UIAlertAction *action = [UIAlertActionactionWithTitle:@"确定"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *action) {
NSLog(@"确定");
// 打印输入框的用户名和密码
NSString *userNameStr = [alertController.textFields[0]text];
NSString *passwordStr = [alertController.textFields[1]text];
NSLog(@"userName is: %@ password is: %@", userNameStr, passwordStr);
}];
action;
})];
// 6. 添加输入框到alertView中,注意,actionSheet是没有办法添加textField的,强行添加会Crash
if (alertController.preferredStyle ==UIAlertControllerStyleAlert) {
// 添加用户名输入框
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
// 给输入框设置一些信息
textField.placeholder = @"请输入用户名";
textField.textAlignment = NSTextAlignmentCenter;
}];
// 添加密码输入框
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"请输入密码";
textField.secureTextEntry = YES;
textField.textAlignment = NSTextAlignmentCenter;
}];
}
// 7. 显示(使用模态视图推出)
[selfpresentViewController:alertController animated:YEScompletion:nil];
}
- UIAlertController UIAlertAction (UIAlertView, UIActionSheet)
- UIAlertController UIAlertAction (UIAlertView, UIActionSheet)(最好)
- UIAlertController(UIActionSheet、UIAlertView)
- UIAlertController(UIAlertView && UIActionSheet)
- iOS--UIAlertView与UIAlertController和UIAlertAction
- UIAlertController,取代UIAlertView和UIActionSheet
- iOS8 UIAlertController 创建UIAlertView以及UIActionSheet
- UIAlertController replaces the UIActionSheet and UIAlertView
- 【UI进阶】UIAlertController替代UIAlertView和UIActionSheet
- UIAlertController VS UIAlertView and UIActionSheet
- UIKit-UIAlertView,UIActionSheet,UIAlertController使用方法(完整版)
- IOS-UIAlertController(UIAlertView和UIActionSheet二合一)
- UIAlertController + UIAlertView + UIActionSheet 弹框显示工具
- iOS UIAlertController代替代替UIAlertView与UIActionSheet
- 【学习ios之路:UI系列】UIAlertView. UIActionSheet 和 UIAlertController
- IOS基础UI之(五)UIAlertView、UIActionSheet和UIAlertController详解
- IOS8以上版本,使用UIAlertController代替 UIActionSheet和UIAlertView
- iOS 8 引入的 UIActionSheet 和 UIAlertView 的替代品 - UIAlertController
- Http详解
- text-indent——首行缩进
- mongodb的增删查改(cmd操作)
- SPSS基础教程:SPSS菜单命令详解
- mybatis的mapper的配置文件的resultMap元素的用法和作用
- UIAlertController UIAlertAction (UIAlertView, UIActionSheet)
- LeetCode 343. Integer Break
- matlab 常用 api(六)
- 关于Webview带参访问服务器
- 微信js-sdk config JavaScript签名
- 虚函数和函数重载
- c++ out_of_range
- FIR滤波器以及吉布斯效应
- 类扩展与分类