IOS之UIActionSheet& UIAlertView

一、UIActionSheet 
UIActionShee用来对指定的事件向用户呈现一系列的操作;也可以用来提示用户确认有些带有危险性的操作;ActionSheet包含一个可选的标题和一个或多个按钮,其中每一个对应于要执行的操作。
1、声明代理<UIActionSheetDelegate>
2、
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"选择操作" delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"删除" otherButtonTitles:@"取消", nil];   
    // 用tag值来分辨是代理方法调用时哪个actionSheet
    sheet.tag = 1;  
    sheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;  
    [sheet showInView:self.view];
     
     
    // 按钮比较多时,将按钮标题放在数组中遍历插入
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"选择操作" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles: nil];
    actionSheet.tag = 2;
    for(NSString *title in array){
        [actionSheet addButtonWithTitle:title];
    }
    [actionSheet showInView:self.view];


#pragma mark - UIActionSheetDelegate
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (actionSheet.tag == 1) {
        NSLog(@"sheet clicked index = %d",buttonIndex);
    }
    else if(actionSheet.tag == 2){
        NSLog(@"actionSheet clicked index = %d",buttonIndex);
    }
     
}
参数解释: 
与导航栏类似,操作表单也支持三种风格 :
UIActionSheetStyleDefault              //默认风格:灰色背景上显示白色文字   
UIActionSheetStyleBlackTranslucent     //透明黑色背景,白色文字   
UIActionSheetStyleBlackOpaque          //纯黑背景,白色文字  


cancelButtonTitle  destructiveButtonTitle是系统自动的两项。
otherButtonTitles是自己定义的项,注意,最后一个参数要是nil:otherButtonTitles:@"第一项", @"第二项",nil;






二、UIAlertView
使用UIAlertView向用户提示一条警告消息,Alert View功能与ActionSheet类似,但是外观上有所不同
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"是否删除" message:@"删除后不可撤销" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
alert.tag = 1;    
[alert show];


#pragma mark - UIAlertViewDelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag==1) {
        NSLog(@"you clicked:%@",[alertView buttonTitleAtIndex:buttonIndex]);
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值