【iPhone代码片段之一】UIActionSheet&UIAlertView的应用

类需要符合<UIActionViewDelegate>协议。

示例代码如下:

- (IBAction)buttonPressed:(id)sender {
    NSLog(@"buttonPressed");
    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:@"您要查看进度情况吗?" 
                                  delegate:self//操作表的代理,按钮被按下时收到通知,然后回调协议中的相关方法
                                  cancelButtonTitle:@"取消"
                                  destructiveButtonTitle:@"确定"
                                  otherButtonTitles:nil];
    [actionSheet showInView:self.view];
}

-(void)actionSheet:(UIActionSheet *)actionSheet 
                    didDismissWithButtonIndex:(NSInteger)buttonIndex{
    NSString *msg = nil;
    UIAlertView *alert = nil;
    if(buttonIndex == [actionSheet destructiveButtonIndex]){
        if(nameField.text.length>0){
            msg = [[NSString alloc] initWithFormat:@"您歇会儿吧,%@,一切正常!",nameField.text];
        }else{
            msg = @"您歇会儿吧,一切正常!";
        }
        alert = [[UIAlertView alloc] initWithTitle:@"搞定了"
                                                        message:msg
                                                       delegate:nil//不需要处理按钮按下事件,将委托设置为空
                                              cancelButtonTitle:@"我知道了"
                                              otherButtonTitles: nil];
    }else if(buttonIndex==[actionSheet cancelButtonIndex]){
        msg = @"呜呜,没搞定呢,还在加班呢!";
        alert = [[UIAlertView alloc] initWithTitle:@"没搞定"
                                                        message:msg
                                                       delegate:nil
                                              cancelButtonTitle:@"靠,继续搞吧!"
                                              otherButtonTitles: nil];
    }
    [alert show];
    [alert release];
    [msg release];
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值