UIActionSheet的简单使用

这是用来弹出多重选项的,并且每个选项还可以自定义事件,这与uialert还不一样。

先看看它长啥样。

 

再说实现过程

在controller的.m中,先实现代理

@interface controllerA<UIActionSheetDelegate>

然后添加事件,比如点击按钮的事件

-(void)clickBtn{
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"添加联系人" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从通讯录添加",@"手动添加",@"从会议通讯录添加", nil];
    
    [sheet showInView:self.view];//在当前view显示action sheet
}
//每个选项的事件
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (0 == buttonIndex) {// 从通讯录添加
        ControllerB *b = [[ControllerB alloc] init];
        b.delegate = self;
        [self presentViewController:b animated:YES completion:nil];
        
    }else if (1 == buttonIndex){// 手动添加
        ControllerC *c = [[ControllerC alloc] init];
        c.delegate = self;
        [self presentViewController:c animated:YES completion:nil];
    }else if (2 == buttonIndex){
        ControllerC *b = [[ControllerC alloc] init];
        c.delegate = self;
        [self presentViewController:c animated:YES completion:nil];
    }

}

cancelButtonTitle destructiveButtonTitle是系统自动的两项。
sheet也可以加到keyWindow中,防止遮挡

[sheet showInView:[UIApplication sharedApplication].keyWindow];

 

转载于:https://www.cnblogs.com/Apologize/p/4362955.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值