【发布时间】:2014-09-12 19:56:35
【问题描述】:
场景
在我的应用程序中,右上角有一个带有“放大镜”图标的导航栏。当用户点击此图标时,导航栏的 titleView 将被 UISearchBar 替换。
我用这段代码添加了搜索栏...
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(-5.0, 0.0, 320.0, 44.0)];
searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
UIView *searchBarView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 310.0, 44.0)];
searchBarView.autoresizingMask = 0;
searchBar.delegate = self;
[searchBarView addSubview:searchBar];
self.navigationItem.titleView = searchBarView;
所有这些都可以完美运行。现在,当用户结束对 UISearchBar 的编辑时,我需要让 UISearchBar 消失,并再次替换为 titleView 的“标题”。
问题
如何删除 UISearchBar 并在编辑后显示导航控制器的标题?
【问题讨论】:
标签: ios uinavigationbar uisearchbar