UIAlertView
UIAlertView是iOS中的提醒视图,以弹出框的形式出现。
UIAlertView更多时候是为了询问用户的下⼀步操作。
// 创建UIAlertView
// 1、开辟空间并初始化视图(初始化时,给出视图位置和⼤大⼩小)。
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"标题" message:@"提示信息" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
// 2、调⽤用UIAlertView的show⽅方法,呈现提⽰示框。
[alertView show];
// 3、释放UIAlertView对象。
[alertView release];
处理UIAlertView点击
处理UIAlertView点击的步骤:
1、将AppDelete作为UIAlertView的delegate
2、AppDelete.h⽂文件接受UIAlertViewDelegate协议
3、AppDelete.m⽂文件实现alertView:clickedButtonAtIndex:⽅方法
// AppDelegate.m
// cancelButton(取消按钮的)index(索引值)为0
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0:
NSLog(@"点了取消,取消按钮的下标为0");
break;
case 1:
NSLog(@"点了确定按钮,确定按钮的下标为1");
break;
default:
break;
}
}