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

  • 相关阅读:
    种类并查集
    51nod 1241 特殊的排序(动态规划)
    NKU 专题一 题解
    51nod 1040 最大公约数之和
    cf #419(div2) C.Karen and Game(贪心)
    BZOJ 2648 SJY摆棋子(KD-Tree)
    BZOJ 4154 [Ipsc2015]Generating Synergy(KD-Tree)
    hdu 2966 In case of failure(KD-tree)
    hdu 6071 Lazy Running(同余最短路)
    hdu 6070 Dirt Ratio(分数规划)
  • 原文地址:https://www.cnblogs.com/PSSSCode/p/5268705.html
Copyright © 2011-2022 走看看