zoukankan      html  css  js  c++  java
  • IOS 学习之UIActionSheet的使用

    UIActionSheet 是IOS中从底部弹出的按钮选项,可以为每一个选择设置触发事件。

    为了快速完成这个例子我们在xcode中建立一个singleview 项目,在窗口中添加一个button用来弹出actionsheet

    1.首先在头文件中声明协议<UIActionSheetDelegate>。

    #import <UIKit/UIKit.h>
    
    @interface sheetviewViewController : UIViewController<UIActionSheetDelegate>
    - (IBAction)showSheet:(id)sender;
    
    @end
    

     2.添加button。

    3.为button建立action连线。

    4.在m文件上添加事件代码,弹出actionsheet

    - (IBAction)showSheet:(id)sender {
        UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                      initWithTitle:@"title,nil时不显示"
                                      delegate:self
                                      cancelButtonTitle:@"取消"
                                      destructiveButtonTitle:@"确定"
                                      otherButtonTitles:@"第一项", @"第二项",nil];
        actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
        [actionSheet showInView:self.view];
    }
    

    5.设置actionsheet的样式。

    actionsheet.actionSheetStyle=UIActionSheetStyleBlackOpaque /UIActionSheetStyleAutomatic /UIActionSheetStyleDefault                               /UIActionSheetStyleBlackTranslucent /UIActionSheetStyleBlackOpaque

    6.显示actionsheet

    调用showInView方法

    7.响应actionsheet方法

    -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        if (buttonIndex == 0) {
            [self showAlert:@"确定"];
        }else if (buttonIndex == 1) {
            [self showAlert:@"第一项"];
        }else if(buttonIndex == 2) {
            [self showAlert:@"第二项"];
        }else if(buttonIndex == 3) {
            [self showAlert:@"取消"];
        } 
    
    }
    

     8.注意事项

    在开发过程中,发现有时候UIActionSheet的最后一项点击失效,点最后一项的上半区域时有效,这是在特定情况下才会发生,这个场景就是试用了UITabBar的时候才有。解决办法:

    在 showView时这样使用,[actionSheet showInView:[UIApplication sharedApplication].keyWindow];或者[sheet showInView:[AppDelegate sharedDelegate].tabBarController.view];这样就不会发生遮挡现象了。

  • 相关阅读:
    MYSQL一对多,两表查询合并数据
    bootstrap瀑布流代码
    os mac apache+php+mysql环境配置
    centos 6.5 服务器安装 (LNMP ntfs文件支持 PHP-RPM CHROOT沙盒)
    在linux下将当前目录文件全部小写含目录名
    Javascript知识汇总------js中容易被忽略的细节(持续更新)
    Javascript知识汇总------js数据类型隐式转换
    下次要写约瑟夫和并查集
    --wrong answer
    --最小生成树
  • 原文地址:https://www.cnblogs.com/jackwuyongxing/p/3514780.html
Copyright © 2011-2022 走看看