我目前正在以UITextField
编程方式加载 - 并尝试在单击“搜索”后使键盘关闭。
我-UITextFeild
将 .m 文件的内部声明为
UITextField *searchTextField;
在 .h 文件中,我确实声明了-UITextField
的委托
@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 colorWithRed:(232.0/255.0) green:(232.0/255.0) blue:(232.0/255.0) alpha:(100.0/100.0)];
searchTextField.clearButtonMode = UITextFieldViewModeNever;
searchTextField.returnKeyType = UIReturnKeySearch;
[searchTextField setKeyboardAppearance:UIKeyboardAppearanceAlert];
[self.view.window addSubview:searchTextField];
[searchTextField becomeFirstResponder];
我在里面添加了代表-viewDidLoad
searchTextField.delegate = self;
但是,当我单击键盘上的“搜索”时,什么也没有发生。我不确定为什么会发生这种情况,我什至通过在你点击返回后记录一些东西来调试它,但没有任何反应。