zoukankan      html  css  js  c++  java
  • iOS

    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];

  • 相关阅读:
    块存储、文件存储、对象存储的区别
    brk 和 sbrk 区别
    【转】海量数据处理:十道面试题与十个海量数据处理方法总结
    C++ STL 里为什么不维护一个 size 成员变量?
    C++对象内存分布详解(包括字节对齐和虚函数表)
    虚函数实现原理
    关于Ubuntu中Could not get lock /var/lib/dpkg/lock解决方案
    Jerasure 1.2A 中的 C 函数 tips
    C++ qsort() 函数调用时实参与形参不兼容的问题解决
    C语言位运算符:与、或、异或、取反、左移与右移详细介绍
  • 原文地址:https://www.cnblogs.com/PSSSCode/p/5268705.html
Copyright © 2011-2022 走看看