IOS 中UIAlertView中获取自定义文本框文字方法

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"保存到" message:@"我的收藏" delegate:selfcancelButtonTitle:@"保存" otherButtonTitles:@"取消", nil];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    UITextField *textField = [alert textFieldAtIndex:0];
    textField.keyboardType = UIKeyboardTypeDefault;
    [alert addSubview:textField];
    [alert show];
    [alert release];

如图:

IOS 中UIAlertView中获取自定义文本框文字方法_第1张图片

实现代理方法

 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
 
for (UIView *view in [alertView subviews])                 {
            if ([view isKindOfClass:[UITextField class]]){
                UITextField *textName = (UITextField *)view;
                NSLog(@"%@",textName.text);
            }
        }
}
转自: http://blog.sina.com.cn/s/blog_94103cd90101c6d3.html

你可能感兴趣的:(IOS 中UIAlertView中获取自定义文本框文字方法)