• UIAlterController 的使用


    相对于IOS8.4之后苹果对提示框做了进一步的封装,这将与之前的提示框有很大的同。

    之前的 UIAlterView  是弹出一个提示框。

    而今天学习的提示框是 通过视图控制器进行弹出,这就意味着,我们可以在这个提示框上添加更多的处理事件,我认为苹果的之所以这样是希望用户能够将提示框的功能发挥的淋漓尽致,效果会更加的炫酷。

    这里仅仅将基础知识写出来,以供查阅与巩固。

     UIAlertController * alterCon = [UIAlertController alertControllerWithTitle:@"提示" message:@"不需要" preferredStyle:UIAlertControllerStyleActionSheet];

        UIAlertAction * alterTion = [UIAlertAction actionWithTitle:@"警告" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        }];

        [alterCon addAction:alterTion];

        [self presentViewController:alterCon animated:NO completion:nil];

     实际上提示的内容是:alterCon 里面定义的提示内容。

    在alterCon 里 有的一个属性值(就是上面写的) :UIAlertControllerStyleActionSheet 是让提示框从底部出现。

    还有一个属性值:UIAlertControllerStyleAlert 是让提示框从中部出现。

    资料参考

    有的时候,我们希望实现如下的效果:

    上面的代码实现的效果的关键源代码:

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
        UIAlertController * alterCon = [UIAlertController alertControllerWithTitle:@"提示" message:@"你好,你可以这样做更好,请【确定】;你好,你可以这样做更好,请【取消】;你好,你可以这样做更好,请【稍后在说】" preferredStyle:UIAlertControllerStyleActionSheet];
        UIAlertAction * alterTion1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"选择了这个——确定");
        }];
        UIAlertAction * alterTion2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"选择了这个——取消");
        }];
        UIAlertAction * alterTion3 = [UIAlertAction actionWithTitle:@"稍后在说" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"选择了这个——稍后再说");
        }];
        [alterCon addAction:alterTion1];
        [alterCon addAction:alterTion2];
        [alterCon addAction:alterTion3];
        [self presentViewController:alterCon animated:NO completion:nil];
    }
     代码

     此外也可以实现下面的效果:

     

    实现效果代码为:

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"添加好友" preferredStyle:UIAlertControllerStyleAlert];
        
        [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
            
        }];
        
        UITextField *textField = alert.textFields[0];
        
        UIAlertAction *queding = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            //  发起好友的添加请求
           
        }];
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        [alert addAction:queding];
        [alert addAction:cancel];
        
        //  显示警示框
        [self presentViewController:alert animated:YES completion:nil];
     代码
  • 相关阅读:
    一步一步实现自己的模拟控件(4)——根控件
    一步一步实现自己的模拟控件(6)——控件树及控件区域
    ATL COM初探(1)
    一步一步实现自己的模拟控件(2)——窗口过程thunk
    一步一步实现自己的模拟控件(3)——Widget驱动
    关于硬盘的一些知识
    Win32中TreeView控件的使用方法,类似于资源管理器中文件树形显示方式
    笔记本双系统XP与Ubuntu,重装XP后如何恢复grup引导,另附操作系统启动过程
    vim常用命令
    MFC中CListCtrl控件的使用方法
  • 原文地址:https://www.cnblogs.com/benpaobadaniu/p/4924632.html
Copyright © 2020-2023  润新知