//按钮点击后,获取按钮的索引值
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
{
case 0: NSLog(@"您点击了取消按钮");
break;
case 1: NSLog(@"您点击了第2个按钮");
break;
case 2: NSLog(@"您点击了第3个按钮");
break;
case 3: NSLog(@"您点击了第4个按钮");
break;
default: break;
}
//实现取消按钮事件的监听
-(void)alertViewCancel:(UIAlertView *)alertView
{
NSLog(@"您点击了取消按钮!==============="); }
}
//响应按钮方法
-(void)showAlert
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"标题" message:@"消息内容" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"Other1",@"Other2",@"Other3", nil];
[alert release];
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Default Alert View" message:@"Defalut" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
UIAlertView使用全解 标准的双按钮,cancel那个buttonIndex 为0, ok button 的buttonIndex为1
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Default Alert View"message:@"Defalut" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",@“ThirdButton”, nil];
UIAlertView使用全解 和程序里的顺序一样,cancel