我目前正在以编程方式加载 -UITextField 并尝试在单击“搜索”后使键盘向下。
我将 .m 文件中的 -UITextFeild 声明为
UITextField *searchTextField;
在 .h 文件中,我确实声明了 -UITextField 的委托(delegate)
@interface firstChannel : UIViewController<LBYouTubePlayerControllerDelegate, UITableViewDelegate,UITableViewDataSource, NSXMLParserDelegate, UITextFieldDelegate, AVPlayerItemOutputPullDelegate>{
这就是我以编程方式添加 UITextField 的方式。
searchTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, -26, 300, 30)];
searchTextField.borderStyle = UITextBorderStyleRoundedRect;
searchTextField.font = [UIFont fontWithName"Heiti TC" size:13];
searchTextField.autocorrectionType = UITextAutocorrectionTypeNo;
searchTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
searchTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
searchTextField.placeholder = @"Search on the Channel";
searchTextField.borderStyle = UITextBorderStyleNone;;
searchTextField.textAlignment = UITextAlignmentCenter;
searchTextField.center = CGPointMake(160, 43);
searchTextField.textColor = [UIColor colorWithRed232.0/255.0) green232.0/255.0) blue232.0/255.0) alpha100.0/100.0)];
searchTextField.clearButtonMode = UITextFieldViewModeNever;
searchTextField.returnKeyType = UIReturnKeySearch;
[searchTextField setKeyboardAppearance:UIKeyboardAppearanceAlert];
[self.view.window addSubview:searchTextField];
[searchTextField becomeFirstResponder];
我在 -viewDidLoad 中添加了委托(delegate)
searchTextField.delegate = self;
但是,当我点击键盘上的“搜索”时,什么也没有发生。我不确定为什么会这样
Best Answer-推荐答案 strong>
在创建和设置文本字段后调用 searchTExtField.delegate 。
关于ios - textFieldShouldReturn 没有被调用(textField 以编程方式加载),我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/18602104/
|