【发布时间】:2011-11-10 17:53:27
【问题描述】:
我添加了一个带有 UINavigationController 的 UISearchBar 和 UISearchDisplayController。因为我们需要导航栏中的一些按钮,所以我创建了一个包含一些按钮的自定义视图,并将其作为 rightBarButtonItem。我注意到当我单击搜索栏时,键盘从底部弹出,并且还将 UINavigationController 的导航栏移出屏幕。所以现在我看不到我在 UISearchBar 中输入的内容。有没有办法解决这个问题?我已经看到其他应用程序看起来像是在导航栏的 LHS 或 RHS 上使用 UINavigationBar + 多个按钮,所以我假设这是可能的。谢谢。
UIButton *homeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
UIImage *house = [UIImage imageNamed:@"icon_house.png"];
[homeButton setImage:house forState:UIControlStateNormal];
[homeButton addTarget:self action:@selector(homePressed:) forControlEvents:UIControlEventTouchUpInside];
UIButton *filterButton = [[UIButton alloc] initWithFrame:CGRectMake(49, 0, 44, 44)];
[filterButton setTitle:@"Filter" forState:UIControlStateNormal];
[filterButton addTarget:self action:@selector(FilterButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
self.SearchEntry = [[[UISearchBar alloc] initWithFrame:CGRectMake(98, 0, 150, 44)] autorelease];
self.SearchEntry.delegate = self;
UISearchDisplayController *searchDisplayCtlr = [[UISearchDisplayController alloc] initWithSearchBar:_searchEntry contentsController:self];
searchDisplayCtlr.searchResultsDataSource = self;
searchDisplayCtlr.searchResultsDelegate = self;
searchDisplayCtlr.delegate = self;
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 248, 44)];
[containerView addSubview:homeButton];
[containerView addSubview:filterButton];
[containerView addSubview:_searchEntry];
【问题讨论】:
标签: iphone uinavigationcontroller