UISearchBar与UINavigationController

时间:2011-11-10 17:53:27

标签: iphone uinavigationcontroller

我添加了一个带有UINavigationController的UISearchBar和UISearchDisplayController。因为我们在navigationBar中需要一些按钮,所以我创建了一个包含几个按钮的自定义视图,并将其作为rightBarButtonItem。我注意到当我点击搜索栏时,键盘从底部弹出,并且还将UINavigationController的navigationBar移出屏幕。所以现在我无法看到我在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];

1 个答案:

答案 0 :(得分:0)

尝试调整contentSize的{​​{1}}。另外,请注意您所采取控件的层次结构。不要将UIScrollViewUINavigationBar保留在UISearchView中,然后它就不会移动并保持固定在他们的位置