问题描述
我有一个UIButton,我正在尝试开发UIButton的可编辑UITextField onclick。
基本上,我希望用户点击按钮编辑文本并保存以备将来使用。
I have a UIButton and I am trying to develop an editable UITextField onclick of UIButton.Basically, I want the user to click on the button and edit the text and save it for future use.
所以目前我有:
[notes_button addTarget:self action:@selector(editNote) forControlEvents:UIControlEventTouchUpInside];
我不知道如何获得像UITextField onclick这样的弹出窗口并在editNote函数中添加UITextField。
I am not sure how to get a popup like UITextField onclick and add UITextField in editNote function.
推荐答案
试试这个。首先让你的文本字段隐藏在viewdidload上 - 然后按下按钮,将其淡入..使其可编辑,并为用户弹出键盘。
Try this. First make your textfield hide on viewdidload - then on button push, fade it in.. make it editable, and pop up keyboard for user.
//viewDidLoad
yourTextField.alpha = 0;
yourTextField.userInteractionEnabled = FALSE;
-(void)editNote {
//fade in text field after button push
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0];
[UIView setAnimationDuration:0.75];
yourTextField.alpha = 1;
[UIView commitAnimations];
//make text field editable
yourTextField.userInteractionEnabled = TRUE;
//pop up keyboard
[yourTextField becomeFirstResponder];
}
-------更新 - -------
现在您已经描述了您想要做得更好一些的事情。您将需要在此新视图控制器上创建一个全新的ViewController,其中包含字段(UITextFields等)。
Now that you have described what you are trying to do a little better. You will want to create an entirely new ViewController with the fields (UITextFields etc) on this new view controller.
点击按钮,您将编码:
TextFieldViewController * vc = [(TextFieldViewController *)[[TextFieldViewController alloc] init] autorelease];
[self.navigationController presentModalViewController:vc animated:YES];
[vc release];
//you will need to create a button on this new ViewController and use this code to dismiss it when done.
[[self parentViewController] dismissModalViewControllerAnimated:YES];
这篇关于如何在点击UIButton时添加UITextfield并使其可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!