来源: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];
原文链接:https://www.oschina.net/question/54100_36098
我来说两句