您的位置:首页 > 产品设计 > UI/UE

UIAlertView上添加输入框UITextField

2015-11-10 18:18 549 查看
UIAlertView上添加输入框UITextField

1、初始化UIAlertView,并添加UITextField

UIAlertView *exitAlertView=[[UIAlertView alloc]initWithTitle:@"退出原因" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

exitAlertView.alertViewStyle=UIAlertViewStylePlainTextInput;

UITextField *reasonField=[exitAlertView textFieldAtIndex:0];

reasonField.placeholder=@"请输入退出原因";

[exitAlertView show];

2、在UIAlertView的代理方法中为确定按钮添加点击事件(前提记得添加UIAlertViewDelegate)

#pragma mark - UIAlertViewDelegate

//为按钮添加点击事件

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

NSLog(@" button index=%ld is clicked.....", buttonIndex);

UITextField *reasonField = [alertView textFieldAtIndex:0];

//_reasonStr 为全局变量的Nsstring,获取UITextField中的输入值

_reasonStr=reasonField.text;

//buttonIndex为1是确定按钮

if (buttonIndex == 1) {

//调用接口

[self postQuitTravel];

[reasonField resignFirstResponder];

}

else{

[reasonField resignFirstResponder];

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: