zoukankan      html  css  js  c++  java
  • iOS 开发

    最近在写项目的时候,发现使用alertview和actonsheet会报警告,所以就查了一下,发现ios 9 以后会使用UIAlertController来进行操作,

    具体代码如下:

    1、声明

    #import "EleventhViewController.h"
    
    @interface EleventhViewController ()
    {
        UIAlertController *_alertController;
    }
    
    @end

    2、使用UIalertController创建的时候,只需要把样式边一样就可以了,如下

    typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
        UIAlertControllerStyleActionSheet = 0, -->上拉菜单
        UIAlertControllerStyleAlert -->警告框
    } NS_ENUM_AVAILABLE_IOS(8_0);

    3、警告框的样式

    typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
        UIAlertActionStyleDefault = 0,-->默认的
        UIAlertActionStyleCancel,-->取消的
        UIAlertActionStyleDestructive -->警告样式,会让字体变成红色
    } NS_ENUM_AVAILABLE_IOS(8_0);

    3、创建alertview

    //alertview的创建
        _alertController = [UIAlertController alertControllerWithTitle:@"请选择操作" message:@"数据删除后无法恢复" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
            //在这里进行操作
            
        }];
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:nil];
        
        [_alertController addAction:cancelAction];
        [_alertController addAction:okAction];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
            
            textField.placeholder = @"请输入车牌号";

        }];
    [self presentViewController:_alertController animated:YES completion:nil];

    4、创建actonsheet

    //actionsheet的创建
        _alertController = [UIAlertController alertControllerWithTitle:@"请选择操作" message:@"数据删除后无法恢复" preferredStyle:UIAlertControllerStyleActionSheet];
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
        UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive handler:nil];
        
        [_alertController addAction:cancelAction];
        [_alertController addAction:okAction];
        [_alertController addAction:deleteAction];
        [self presentViewController:_alertController animated:YES completion:nil];

    5、具体点击方法的实现的话,和alertview标注的一样

    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
            //在这里进行操作
            
        }];
  • 相关阅读:
    BZOJ 2073: [POI2004]PRZ [DP 状压]
    POJ 2404 Jogging Trails [DP 状压 一般图最小权完美匹配]
    BZOJ 2595: [Wc2008]游览计划 [DP 状压 斯坦纳树 spfa]【学习笔记】
    BZOJ 1226: [SDOI2009]学校食堂Dining [DP 状压]
    BZOJ 2734: [HNOI2012]集合选数 [DP 状压 转化]
    BZOJ 1097: [POI2007]旅游景点atr [DP 状压 最短路]
    BZOJ 1072: [SCOI2007]排列perm [DP 状压 排列组合]
    USACO 状压DP练习[3]
    CF781D Axel and Marston in Bitland [倍增 矩阵乘法 bitset]
    Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)
  • 原文地址:https://www.cnblogs.com/hero11223/p/5695286.html
Copyright © 2011-2022 走看看