if (customAlertView==nil) {
customAlertView = [[UIAlertView alloc] initWithTitle:@"自定义服务器地址" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil nil];
}
[customAlertView setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
UITextField *nameField = [customAlertView textFieldAtIndex:0];
nameField.placeholder = @"请输入一个名称";
UITextField *urlField = [customAlertView textFieldAtIndex:1];
[urlField setSecureTextEntry:NO];
urlField.placeholder = @"请输入一个URL";
urlField.text = @"http://";
[customAlertView show];
实现UIAlertViewDelegate
在CODE上查看代码片派生到我的代码片
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == alertView.firstOtherButtonIndex) {
UITextField *nameField = [alertView textFieldAtIndex:0];
UITextField *urlField = [alertView textFieldAtIndex:1];
//TODO
}
}
- 7
效果图: