【发布时间】:2012-12-04 15:20:19
【问题描述】:
我想向 UICollectionViewController 添加一个搜索栏,其嵌入方式如下: UItabbarController > UINavigationbarController > UICollectionViewController > SearchBar (!) 在此视图中,搜索栏将取代 NavigationBar。
在相同的设计下,如果我使用 UITableViewController 测试上述内容,搜索栏显示正常(通过编程和故事板)
问题是当我使用 StoryBoard 框架时,我无法在 UICollectionViewController 上添加搜索栏;它只是位于视图的中间,我不知道如何将它移动到顶部。另外,它总是出现在 UICollectionview 下方,所以它是不可见的。
因此,以编程方式采取另一条路线:
-(void)viewWillAppear:(BOOL)animated{
self.searchBarTop = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[self.searchBarTop setPlaceholder:@"Enter your command here"];
self.searchDC = [[UISearchDisplayController alloc]initWithSearchBar:self.searchBarTop contentsController:self];
self.searchBarTop.delegate = self;
[[self navigationController] setNavigationBarHidden:NO animated:animated];
[self.navigationController.navigationBar addSubview:self.searchBarTop];
}
这样,搜索栏就可以正常显示了。但不幸的是,当我输入一些文本时,它会在视图上方消失 - 大概是因为底层 navBar 这样做了 - (不知道为什么......)
我不确定为什么搜索栏可以使用 UITableViewController,以及为什么 UICollectionViewController 会如此痛苦。 也就是说,任何人都知道为什么搜索栏/导航栏消失了,我该如何解决这个问题?
欢迎任何解决方案..
谢谢! -A
【问题讨论】:
标签: ios uinavigationcontroller uisearchbar uicollectionview