2014-09-12 69 views
1

情景iOS装置:除去编程方式添加搜索栏从导航栏

在我的应用程序存在与在上部右手侧一个“放大镜”图标的导航条。当用户点击此图标时,导航栏的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和显示标题为编辑后的导航控制器?

回答

0

试试这个,

searchBar.hidden = Yes; 
+1

“......和显示标题为编辑后的导航控制器?” – 2014-09-12 20:42:07

0

我没有测试过,但是这应该工作:

[self.navigationItem.titleView removeFromSuperview]; 
self.title = @"Nav bar title";