前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >iOS UIAlertView 的基本使用方法

iOS UIAlertView 的基本使用方法

作者头像
静静的晨光
修改2020-06-04 10:33:38
1.5K0
修改2020-06-04 10:33:38
举报
文章被收录于专栏:ios2020ios2020

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

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

创建和显示UIAlertView

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

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

处理UIAlertView按钮事件

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

代码语言:txt
复制
[@interface](http://my.oschina.net/interface) MyClass : NSObject <UIAlertViewDelegate>

在MyClass实现体中实现:

代码语言:txt
复制
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        NSLog(@"点击了确定按钮");
    }
    else {
        NSLog(@"点击了取消按钮");
    }
}
代码语言:txt
复制
UIAlertView *alert = [[UIAlertView alloc]
                     initWithTitle:@"提示信息"
                     message:@"确定订阅开发笔记的博客吗?"
                     delegate:self
                     cancelButtonTitle:@"取消",
                     otherButtonTitles:@"确定",nil];
// 显示
[alert show];
[alert release];

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档