Pio*_*otr 4 iphone objective-c uisearchbar uisearchbardelegate
我一直试图找到解决方案几个小时,但没有骰子...我一直在尝试纯粹以编程方式实现UISearchBar(没有xib,没有接口构建器).
这是我的.h标题:
@interface RLCASearchMasterViewController : UIViewController<UISearchBarDelegate>
@property (strong, nonatomic) RLCAGUIElements *gui;
@property (strong, nonatomic) RLCAUITableView *table;
@property (strong, nonatomic) UISearchBar *searchBar;
@end
Run Code Online (Sandbox Code Playgroud)
和我的.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];
}
Run Code Online (Sandbox Code Playgroud)
我已经过了这个我不知道多少次,并且不知道我做错了什么... UISearchBar被添加到视图中,具有正确的大小和所有,但是当点击/点击时,键盘没有出现.如果我唤起以下内容:
[searchBar becomeFirstResponder];
Run Code Online (Sandbox Code Playgroud)
键盘确实显示,所以它可能不是委托,但实际上检测它是否被点击...我不希望它在加载时编辑,并且只能通过请求...
请帮忙.谢谢!:)
真诚的,彼得.
好的,我得到了它的工作.
它有效,但我不明白为什么.如果有人有任何见解,我将非常感激......
所以:
我换了:
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];
Run Code Online (Sandbox Code Playgroud)
有:
searchBar = [[UISearchBar alloc] init];
searchBar.delegate = self;
[searchBar sizeToFit];
[self.view addSubview:searchBar];
Run Code Online (Sandbox Code Playgroud)
...... aaand,VIOLA!;)
感谢所有的答案,并且正如所提到的,将会理解为什么这有效以及它做了什么.
一切顺利,Piotr.
| 归档时间: |
|
| 查看次数: |
3940 次 |
| 最近记录: |