UIActionSheet使用

UIActionSheet是IOS系统提供的选择提示项,效果如下图:


使用很方便,每一项点击都可以在代理中监听到,不用考虑适配问题,代码如下:

UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:nil
     delegate:self
     cancelButtonTitle:@"取消"
     destructiveButtonTitle:nil
     otherButtonTitles:@"拍照",@"从手机相册选择", nil];
     [as showInView:self.navigationController.view];
使用注意点:

1.initWithTitle为初始化方法,参数title表示标题,可以设置成nil不显示

2.cancelButtonTitle为取消按钮,点击后UIActionSheet消失

3.可以更具实际情况自己增加按钮。使用otherButtonTitle是设置

4.如果想使用代理,控制器继承UIActionSheetDelegate,一般实现clickedButtonAtIndex方法即可

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        
    }else if (buttonIndex == 1) {
        
    }
}
buttonIndex代表点击UIActionSheet的哪一项,然后根据判断写逻辑即可。

5.在某些特殊情况下,UIActionSheet的otherButtonTitles不是固定的,需要根据实际情况变化;我们可以使用如下方法添加:

UIActionSheet *mySheet = [[UIActionSheet alloc] initWithTitle:@"请选择"
                                                    delegate:self
                                           cancelButtonTitle:@"取消"
                                      destructiveButtonTitle:nil
                                           otherButtonTitles:nil];
    NSMutableArray *jlInfos=[FMUserInfo sharedInstance].jlInfos;
    NSString *rsName=@"";
    for(FMJlInfo *info in jlInfos){
        if(![Tools isBlankString:info.resumeName]){
            rsName=info.resumeName;
        }
        <span style="color:#ff6666;">[mySheet addButtonWithTitle:rsName];</span>
    }
    [mySheet showInView:self.navigationController.view];
[mySheet addButtonWithTitle:rsName];即是代码添加方法




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值