zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Oracle 11g SQL Fundamentals Training Introduction02
    Chapter 05Reporting Aggregated data Using the Group Functions 01
    Chapter 01Restriicting Data Using The SQL SELECT Statemnt01
    Oracle 11g SQL Fundamentals Training Introduction01
    Chapter 04Using Conversion Functions and Conditional ExpressionsConditional Expressions
    Unix时代的开创者Ken Thompson (zz.is2120.bg57iv3)
    我心目中计算机软件科学最小必读书目 (zz.is2120)
    北京将评估分时分区单双号限行 推进错时上下班 (zz)
    佳能G系列领军相机G1X
    选购单反相机的新建议——心民谈宾得K5(转)
  • 原文地址:https://www.cnblogs.com/yyt-hehe-yyt/p/4741833.html
Copyright © 2011-2022 走看看