现在的位置: 首页 > 综合 > 正文

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

2018年02月13日 ⁄ 综合 ⁄ 共 637字 ⁄ 字号 评论关闭

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 <wbr>中UIAlertView中获取自定义文本框文字方法

实现代理方法

 

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

抱歉!评论已关闭.