如果我点击图像,我可以弹出UITextfield
来输入数据吗?我该怎么做?
最佳答案
您可以按如下方式使用 UIAlertView:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title"
message:@"Please enter your text:"
delegate:self
cancelButtonTitle:@"Done"
otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *textField = [alert textFieldAtIndex:0];
textField.keyboardType = UIKeyboardTypeDefault;
textField.placeholder = @"Enter some text";
[alert show];
编辑:为了处理返回的文本,实现委托(delegate)方法
- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex > 0) {
UITextField *textField = [alert textFieldAtIndex:0];
NSString *text = textField.text;
if(text == nil) {
return;
} else {
//do something with text
}
}
}
关于ios - 如何在点击图像时弹出 UITextField 以输入数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10928984/