1.增加委托,在头文件中增加以下代码:
UIViewController<UIAlertViewDelegate>
2.定义对象及委托处理方法
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示"
message:@"网络差,请重试!"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"重试",nil];//otherButtonTitles不可修改名称
[alertView show];
3.添加默认的处理方法- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
UIView *view = (UIView*)[self.view viewWithTag:120];
switch (buttonIndex) {
case 0:
[view removeFromSuperview];
break;
case 1:
[self viewDidLoad];
break;
default:
break;
}
}