是否可以在故事板中的UISearchbar和导航项之间添加视图?如果我添加一个视图然后添加UISearchbar,则UISearchbar将成为视图的子项。唯一的问题是在tableview搜索之后,视图的内容被隐藏。
由于
答案 0 :(得分:1)
您可以在iOS 7中执行此操作:
UISearchDisplayController
控制器在viewDidLoad
:
- (void)viewDidLoad
{
[super viewDidLoad];
// Set the displaysSearchBarInNavigationBar property
self.searchDisplayController.displaysSearchBarInNavigationBar = YES;
// Sample custom view for demonstration purposes
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
customView.backgroundColor = [UIColor redColor];
// Create a UIBarButtonItem with your custom view
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:customView];
self.navigationItem.leftBarButtonItem = item;
}
产生这个(红色方块是自定义视图):