1.实例化
UIAlertView *view=[[UIAlertView alloc]initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"other", nil];
如果需要监听弹出以后的点击事件,需要设置代理 UIAlertViewDelegate
2.常用属性
可以设置弹出为输入框,如下属性
[view setAlertViewStyle:UIAlertViewStylePlainTextInput];
UITextField *t1=[view textFieldAtIndex:0];
UITextField *t2=[view textFieldAtIndex:1];
t1.keyboardType=UIKeyboardTypeNumberPad;
t2.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
[view addButtonWithTitle:@"Test"];
[view cancelButtonIndex];
[view firstOtherButtonIndex];
3.代理方法
#pragma mark --UIAlertViewDelegate--
//根据被点击按钮的索引处理点击事件
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"%ld",(long)buttonIndex);
NSString *login= [alertView textFieldAtIndex:0].text;
//NSString *pwd=[alertView textFieldAtIndex:1].text;
NSLog(@"%@.....",login);
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
//AlertView已经消失时执行的事件
}
-(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
//ALertView即将消失时的事件
}
- (void)alertViewCancel:(UIAlertView *)alertView
{
//AlertView的取消按钮的事件 (Home按钮)
}
-(void)didPresentAlertView:(UIAlertView *)alertView
{
//AlertView已经显示时的事件
}
-(void)willPresentAlertView:(UIAlertView *)alertView
{
//AlertView即将显示时
}