服从UIAlertViewDelegate 协议




Title : 标题
message : 提示消息
delegate : 代理
cancelButtonTitle : 取消显示
otherButtonTitles : 其他按钮显示文字,只给出按钮显示的文字即可,可多个


UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"警告"
message:@"手机号码输入错误"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定",@"sure", nil];

UIAlertViewStyleDefault = 0, 默认

UIAlertViewStyleSecureTextInput, 密码

UIAlertViewStylePlainTextInput, 输入框

UIAlertViewStyleLoginAndPasswordInput 登录,密码


alertView.alertViewStyle = UIAlertViewStyleSecureTextInput;

[alertView show]; 让alertView 弹出

[alertView release];







当点击 alertView 上 button时 触发的方法.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
取消按钮的buttonindex 为 0
其他的按钮从左往右依次 + 1 ;


通过switch..case 匹配是哪一个按钮按下
switch (buttonIndex) {
case 0:
NSLog(@"取消");
break;
case 1:
NSLog(@"确定");
break;
case 2:
NSLog(@"sure");
break;
default:
break;
}
}




当我们取消一个视图(如。用户单击按钮)。这不是用户单击取消按钮时调用。

如果没有定义的委托,我们模拟点击取消按钮

- (void)alertViewCancel:(UIAlertView *)alertView;


- (void)willPresentAlertView:(UIAlertView *)alertView;

动画和之前显示视图


- (void)didPresentAlertView:(UIAlertView *)alertView;

动画后


- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex;

之前动画和隐藏视图


- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;

动画后

- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView;

编辑的任何违约后称为字段添加的风格