UIActionSheet学习

本文深入探讨了在iOS应用开发中从UIActionSheet到UIAlertController的过渡过程,详细解释了如何使用UIAlertController实现相似功能,包括其构造方法、重要属性、方法以及常用的委托方法,旨在帮助开发者平滑迁移并提高应用的用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

UIActionSheet是在iOS弹出的选择按钮项,可以添加多项,并为每项添加点击事件。

要遵循UIActionSheetDelegate协议;

#import<UIKit/UIKit.h>


需注意:

Important: UIActionSheet is deprecated in iOS 8. (Note that UIActionSheetDelegate is also deprecated.) To create and manage action sheets in iOS 8 and later, instead use UIAlertController with a preferredStyle of UIAlertControllerStyleActionSheet.

如上所示,在IOS8.0及以后 版本中不再支持UIActionSheet,以后的研究下用UIAlertController实现的方法

 

重要的属性及方法:

  1. - (instancetype)initWithTitle:(NSString *)title//标题

                     delegate:(id<UIActionSheetDelegate>)delegate//委托对象,需满足UIActionSheetDelegate协议,可设为nil

            cancelButtonTitle:(NSString *)cancelButtonTitle//取消标题

       destructiveButtonTitle:(NSString *)destructiveButtonTitle//‘确认标题

            otherButtonTitles:(NSString *)otherButtonTitles//其他按钮标题,可以是一组

,  //构造方法

  1. @property(nonatomic, copy) NSString *title //标题;
  2. @property(nonatomic) UIActionSheetStyle actionSheetStyle //显示风格,可选项如下
    1. UIActionSheetStyleAutomatic=-1
    2. UIActionSheetStyleDefault=UIBarStyleDefault
    3. UIActionSheetStyleBlackTranslucent=UIBarStyleBlackTranslucent
    4. UIActionSheetStyleBlackOpaque=UIBarStyleBlackOpaque
  3. - (NSInteger)addButtonWithTitle:(NSString *)title //增加一个按钮
  4. @property(nonatomic, readonly) NSInteger numberOfButtons//按钮总数,意义不大
  5. @property(nonatomic) NSInteger cancelButtonIndex//取消按钮的序号,可用来确定当按下是不是取消按钮
  6. @property(nonatomic) NSInteger destructiveButtonIndex//‘确认按钮序号,可用来确定当按下是不是‘确认’按钮
  1. - (void)showInView:(UIView *)view // view The view from which the action sheet originates.

 

常用委托方法:

  1. - (void)actionSheet:(UIActionSheet *)actionSheet

didDismissWithButtonIndex:(NSInteger)buttonIndex

Parameters

actionSheet

The action sheet that was dismissed.

buttonIndex

The index of the button that was clicked. The button indices start at 0. If this is the cancel button index, the action sheet is canceling. If -1, the cancel button index is not set.

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值