iOS UIAlertView 的基本使用方法

来源:https://www.oschina.net/question/54100_36098

UIAlertView常用于应用界面信息警告提示。

创建和显示UIAlertView

下面显示一个带有“取消”和“确定”两个按钮的的UIAlertView提示对话框。

下面显示一个带有“取消”和“确定”两个按钮的的UIAlertView提示对话框。
UIAlertView *alert = [[UIAlertView alloc]
                     initWithTitle:@"提示信息"
                     message:@"确定订阅开发笔记的博客吗?"
                     delegate:nil
                     cancelButtonTitle:@"取消",
                     otherButtonTitles:@"确定",nil];
// 显示
[alert show];
[alert release];

处理UIAlertView按钮事件

通常需要处理用户点击UIAlertView的按钮后的事件,比如用户点击了“确定”和“取消”按钮后,就需要处理不同的程序功能。要接收UIAlertView的按钮事件,则得要在类中处理UIAlertViewDelegate。如:

[@interface](http://my.oschina.net/interface) MyClass : NSObject <UIAlertViewDelegate>

在MyClass实现体中实现:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        NSLog(@"点击了确定按钮");
    }
    else {
        NSLog(@"点击了取消按钮");
    }
}
UIAlertView *alert = [[UIAlertView alloc]
                     initWithTitle:@"提示信息"
                     message:@"确定订阅开发笔记的博客吗?"
                     delegate:self
                     cancelButtonTitle:@"取消",
                     otherButtonTitles:@"确定",nil];
// 显示
[alert show];
[alert release];
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值