选择项弹窗IOS中UIActionSheet

IOS8后虽然出了新的控制器UIAlertController,但之前的UIAlertView,UIActionSheet依然可以使用。

一、初始化方法

- (instancetype)initWithTitle:(NSString *)title delegate:(id<UIActionSheetDelegate>)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...;

参数说明:

title:视图标题

delegate:设置代理

cancelButtonTitle:取消按钮的标题

destructiveButtonTitle:特殊标记的按钮的标题

otherButtonTitles:其他按钮的标题

二、常用方法和属性介绍

@property(nonatomic,copy) NSString *title;

设置标题

@property(nonatomic) UIActionSheetStyle actionSheetStyle;

设置风格,枚举如下:

typedef NS_ENUM(NSInteger, UIActionSheetStyle) {

    UIActionSheetStyleAutomatic        = -1,      

    UIActionSheetStyleDefault          = UIBarStyleDefault,

    UIActionSheetStyleBlackTranslucent = UIBarStyleBlackTranslucent,

    UIActionSheetStyleBlackOpaque      = UIBarStyleBlackOpaque,

};

- (NSInteger)addButtonWithTitle:(NSString *)title;

添加一个按钮,会返回按钮的索引

- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;

获取按钮标题

@property(nonatomic,readonly) NSInteger numberOfButtons;

获取按钮数量

@property(nonatomic) NSInteger cancelButtonIndex;

设置取消按钮的索引值

@property(nonatomic) NSInteger destructiveButtonIndex;

设置特殊标记

@property(nonatomic,readonly,getter=isVisible) BOOL visible;

视图当前是否可见

下面是几种弹出方式,会根据风格不同展现不同的方式

- (void)showFromToolbar:(UIToolbar *)view;

- (void)showFromTabBar:(UITabBar *)view;

- (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated ;

- (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated ;

- (void)showInView:(UIView *)view;

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;

使用代码将视图收回

三、UIActionSheet代理方法

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

点击按钮时触发的方法

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

视图将要弹出时触发的方法

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

视图已经弹出式触发的方法

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

点击按钮后,视图将要收回时触发的方法

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

点击按钮后,视图已经收回时触发的方法

时间: 2024-07-30 17:05:20

选择项弹窗IOS中UIActionSheet的相关文章

ios中UIActionSheet的误区

今天在研究UIActionSheet  直接把代码放到viewDidLoad中来执行,费了半天的劲总是出现问题,也怀疑过是不是xcode的问题,后来发现平时用都是放到一个button的方法里来操作,于是有个观点产生UIActionSheet必须配合动作时才有效果.于是去查看开发文档,上面有句话也验证了观点:Action sheets display a set of buttons representing several alternative choices to complete a ta

IOS中UIActionSheet使用详解

IOS中UIActionSheet使用方法详解 一.初始化方法 - (instancetype)initWithTitle:(NSString *)title delegate:(id<UIActionSheetDelegate>)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:

IOS中UIActionSheet使用方法详解

一.初始化方法 - (instancetype)initWithTitle:(NSString *)title delegate:(id<UIActionSheetDelegate>)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSString *)otherButtonT

CentOS6.9-zabbix3.2启动失败原因及页面没有mysql选择项

环境内核信息: [[email protected]01 ~]# uname -a Linux lodboyedu-01 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux zabbix启动失败的原因 启动时出这 个错误: [[email protected] zabbix-3.2.7]# /etc/init.d/zabbix_server start /usr/loca

解决QML开发中ComboBox中一个已选择项没有清除的问题

解决QML开发中ComboBox中一个已选择项没有清除的问题 近期使用QML开发一个项目.须要使用ComboBox进行显示.当进行一个操作时,须要向ComboBox加入一个元素,当进行另外一个操作时.须要清除ComboBox里面的元素. 可是在操作的过程中,出现了一个诡异的现象--ComboBox里面的已选择项并没有清除. 以下是程序的截图,能够看到.ComboBox中已选择项并没有删除.可是ComboBox中的候选项已经删除了. 我在QTCN上进行提问.后面再大家的努力下,最终把这个问题攻克了

iOS开发——UI篇&amp;下拉弹出列表选择项效果

下拉弹出列表选择项效果 右边菜单中的按键,点击弹出一个列表可选择,选择其中一个,响应相应的事件并把文字显示在右边的菜单上:弹出下拉效果使用LMDropdownView插件,可以用POD进行加载pod ‘LMDropdownView’:LMDropdownView是把想要的视图赋给它: 源代码地址:https://github.com/JxbSir/YiYuanYunGou 效果如下: 1:在主页面先定义按键跟绑定视图(没写全的都是属性中定义了比如btnRigth,dropdownView等):

ios中注意项

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 1.当导入第三方库出现不支持ARC模式,可以在项目->Build Phases中对第三方类文件添加Compiler Flags(-fno-objc-arc) 2.获取UITableViewCell中所有子控件 // 获取当前tableView中的所有cell NSArray *array = [self.tableView visibleCells]; for (NSInteger i

使ListView控件中的选择项高亮显示

实现效果: 知识运用: ListView控件的SelectedItems属性 //获取在ListView控件中被选中数据项的集合 public ListView.SelectedListViewItemCollection SelectedItems{get;} 和ListViewItem数据项的BackColor属性 //获取或设置该数据项的背景色 public Color BackColor{get;set;} 实现代码: private void select_flash_Load(obj

Chosen中选择项的更新

Chosen 选择项的动态修改/更新 如果你需要去动态更新select选择框里的选择项,你需要通知Chosen去响应这个变动,你需要在这个选项框是触发一个"liszt:updated"事件,这样Chosen就会对更新过内容后的select选择框重新进行渲染. jQuery 版:$("#form_field").trigger("liszt:updated"); Prototype 版:Event.fire($("form_field&q