您的位置:首页 > 产品设计 > UI/UE

IOS开发之UI——UIAlertView使用

2014-11-03 15:37 435 查看
首先,视图控制器必须得实现协议UIAlertViewDelegate中的方法,并指定delegate为self,才能使弹出的Alert窗口响应点击事件。
具体代码如下:

ViewController.h中的代码如下:
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIAlertViewDelegate>

@end


在点击事件中,添加如下代码即可弹出UIAlertView。

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"主意", nil)
message:NSLocalizedString(@"你确定要删除记录吗?", nil)
delegate:self
cancelButtonTitle:NSLocalizedString(@"确定", nil)
otherButtonTitles:NSLocalizedString(@"取消", nil),nil];
[alert show];
[alert release];


确定取消的事件,重写如下方法:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
{
int tag = buttonIndex;
if (tag == 0) {
[arearecode removeAllObjects];
[timerecode removeAllObjects];
[happenrecode removeAllObjects];
[self showhappenview];
}else{
return ;
}
}


这个控件比较简单。只是贴点代码记录一下而已。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: