【发布时间】:2012-06-12 06:42:32
【问题描述】:
我已经尝试找到解决方案好几个小时了,但可惜没有骰子... 我一直在尝试纯粹以编程方式实现 UISearchBar(没有 xib,没有界面构建器)。
这是我的 .h 标头:
@interface RLCASearchMasterViewController : UIViewController<UISearchBarDelegate>
@property (strong, nonatomic) RLCAGUIElements *gui;
@property (strong, nonatomic) RLCAUITableView *table;
@property (strong, nonatomic) UISearchBar *searchBar;
@end
和我的 .m 实现:
@synthesize searchBar;
- (void)loadView
{
[super loadView];
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, searchBar.frame.size.height)];
searchBar.delegate = self;
[self.view addSubview:searchBar];
}
我已经经历了不知道多少次,也不知道我做错了什么...... UISearchBar 以正确的大小和所有内容添加到视图中就好了,但是当单击/点击时,键盘不会出现。 但是,如果我唤起以下内容:
[searchBar becomeFirstResponder];
键盘确实显示,所以它可能不是委托,而是实际检测它是否被点击...我不希望它在加载时进行编辑,并且只能根据请求...
请帮忙。谢谢! :)
真诚地, 彼得。
【问题讨论】:
-
它是否在任何其他视图之下?他们可能会阻止它的接触。
-
我不认为它在任何视图下 - 我已经从所有视图中删除了所有 [UIColor clearColor] 背景以进行检查,似乎没有任何东西覆盖它......
标签: iphone objective-c uisearchbar uisearchbardelegate