• UIActionSheet


      我感觉UIActionSheet和UIAlertView的用法差不多,都很简单,下面给出一个简单的Demo,具体想用哪个,根据公司要求和个人爱好。

    #import "ViewController.h"

    @interface ViewController ()<UIActionSheetDelegate>

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

        button.frame = CGRectMake(100, 100, 100, 40);

        button.backgroundColor = [UIColor orangeColor];

        [button setTitle:@"弹出操作表" forState:UIControlStateNormal];

        [button addTarget:self action:@selector(showActionSheet:) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:button];

    }

    - (void)showActionSheet:(UIButton*)button {

      //destructiveButton是红色按钮,是ActionSheet支持的一种所谓的销毁按钮,对用户的某种行为起到警示作用,比如修改、删除某个东西
      //destructiveButton,1,2,3,Cancel,它们的buttonIndex分别为0,1,2,3,4

        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"呵呵" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"destructiveButton" otherButtonTitles:@"1",@"2",@"3", nil];

        [actionSheet showInView:self.view];

    }

    // Called when a button is clicked. The view will be automatically dismissed after this call returns

    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

        if (0 == buttonIndex) {

            NSLog(@"0");

        } else if (1 == buttonIndex) {

            NSLog(@"1");

        } else if (2 == buttonIndex) {

            NSLog(@"2");

        } else if (3 == buttonIndex) {

            NSLog(@"3");

        } else {

            NSLog(@"4");

        }

    }

      

    - (void)willPresentActionSheet:(UIActionSheet *)actionSheet{

        NSLog(@"willPresentActionSheet");

    }// before animation and showing view

    - (void)didPresentActionSheet:(UIActionSheet *)actionSheet{

        NSLog(@"didPresentActionSheet");

    }// after animation

    - (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex{

        NSLog(@"willDismissWithButtonIndex");

    }// before animation and hiding view

    - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{

        NSLog(@"didDismissWithButtonIndex");

    }// after animation

    @end

  • 相关阅读:
    mysql 存储过程中的 prepare语句(存储过程中动态增减表字段)
    MYSQL创建分区时候报错
    mysql存储过程调试方法
    磁力块[分块]
    区间最优覆盖问题[差分]
    区间最优覆盖问题[差分]
    导弹防御[差分]
    导弹防御[差分]
    CF10D LCIS[动态规划]
    CF10D LCIS[动态规划]
  • 原文地址:https://www.cnblogs.com/yyt-hehe-yyt/p/4741833.html
Copyright © 2020-2023  润新知