iOS7实现带文本输入框的UIAlertView及获取TextField文本内容

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  
    }     
}  

效果图:
这里写图片描述

你可能感兴趣的:(iOS/Mac,iOS,AlertView)