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];
如图:
实现代理方法
- (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); } } }