我有一个编程创建的UITextField添加到NavigationController中,如下所示(在UITableViewController中,因为我希望顶部有一个自定义的固定搜索栏)。
在.h文件中
@property (nonatomic, strong) UITextField *searchText;在.m文件中
@synthesize searchText;
self.searchText = [[UITextField alloc] init];
self.searchText.frame = CGRectMake(35, 234, 250, 27);
self.searchText.backgroundColor = Rgb2UIColor(255, 255, 255);
[self.navigationController.view addSubview:self.searchText];
self.searchText.delegate = self;但是,下列任何方法都不会被触发
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
}
-(void)textFieldDidBeginEditing:(UITextField *)textField{
self.searchText.returnKeyType = UIReturnKeySearch;
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
}有人能告诉我为什么我的代表不工作的正确方向吗?
发布于 2014-10-06 05:03:45
最好使用对象面板中的uiseachbar。这带有默认的搜索栏样式和效果,但类似于uitextfield。您可以设置委托并以与文本视图相同的方式侦听它。
https://stackoverflow.com/questions/26210162
复制相似问题