点击按钮弹出警示框
- (IBAction)login:(UIButton *)sender {
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"输入账号密码" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];//delegate属性赋值为self,也就是view controller,所以在view controller中需要实现代理功能,就是alert view: :
alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:
(NSInteger)buttonIndex{
switch (buttonIndex) {
case 0:
NSLog(@"Cancel button clicked");
break;
case 1:{
NSLog(@"OK button clicked");
UITextField * text1 = [alertView textFieldAtIndex:0];
UITextField * text2 = [alertView textFieldAtIndex:1];
NSLog(@"账号为:%@",text1.text);
NSLog( @"%@",text2.text);
_textt.text = text1.text;
//_textt.textContainer = text2.text
//[_textt.text stringByAppendingFormat:@"%@",text2.text];
//取警示框上的数据
break;
}
default:
break;
}
}
//不断弹出
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{//这里弹出一个警示框的时候,点击确定时,又会调用委托对象的方法,而此处委托用的是和前一个委托相同,所以会调用相同的方法,报错
UIAlertView * alert1 = [[UIAlertView alloc]initWithTitle:@"密码错误!!!" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
alert1.alertViewStyle = UIAlertViewStyleDefault;
[alert1 show];
// UITextView
//下面是自己写的,搞恶作剧用,不断弹出警示框,可以写上各种信息,最后来一个自动关机之类的动作。
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"输入账号密码" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[alert show];
}