第十三天 IOS UIAlertView
UIAlertview的使用:
首先就是拖动一个Button按钮然后就是生成一个单击的方法
这个方法是在方法的实现中写的后最名师.m的
- (IBAction)showAlertDialogClick:(id)sender {
// NSLog(@"show Alert Dialog");
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
[alert show ];
}
然后再后最名.h的方法里继承一个代理
@interface ViewController : UIViewController<UIActionSheetDelegate>
然后在.m 里面写
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0:
NSLog(@"Cancel");
break;
case 1:
{
UITextField *filed;
filed=[alertView textFieldAtIndex:0];
NSString *userName=filed.text;
filed=[alertView textFieldAtIndex:1];
NSString *password=filed.text;
NSLog(@"%@,%@",userName,password);
}
break;
default:
break;
}
}
这样就可以实现弹出对话框

2、showDialogAlertLoginStyle
- (IBAction)showAlertDialogStyleClick:(id)sender {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Lgion" message:nil delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"Lgion", nil];
alert.alertViewStyle=UIAlertViewStyleLoginAndPasswordInput;
[alert show];
}
然后再后最名.h的方法里继承一个代理
@interface ViewController : UIViewController<UIActionSheetDelegate>
然后在.m 里面写
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0:
NSLog(@"Cancel");
break;
case 1:
{
UITextField *filed;
filed=[alertView textFieldAtIndex:0];
NSString *userName=filed.text;
filed=[alertView textFieldAtIndex:1];
NSString *password=filed.text;
NSLog(@"%@,%@",userName,password);
}
break;
default:
break;
}
}
如图:


浙公网安备 33010602011771号