[英]How to add NavigationBar (without NavigationController) and SearchBar to a TableView
I get the feeling this really shouldn't be giving me as much trouble as it is and that I'm missing something, but I just can't seem to get this to work. 我觉得这真的不应该给我带来的麻烦和我错过的东西,但我似乎无法让它发挥作用。 So I want a TabBar that switches between 3 different TableViews.
所以我想要一个在3个不同的TableView之间切换的TabBar。 All of them need to have a NavigationBar but not a NavigationController (as it's all taking place after an initial modal segue into the TabBarController).
所有这些都需要一个NavigationBar而不是一个NavigationController(因为它都是在初始模态进入TabBarController之后发生的)。 the perfect example of what I'm after is the Apple Maps bookmarks.
我所追求的完美例子是Apple Maps书签。
I've tried three different methods all of which have failed in different ways: 我尝试了三种不同的方法,所有这些方法都以不同的方式失败了:
I've implemented most of my interface in the IB so far and would like to keep it that way as much as possible, but I'm sure there must be something obvious I'm missing here. 到目前为止,我已经在IB中实现了我的大部分界面,并且希望尽可能地保持这种方式,但我确信必须有一些明显我在这里缺失的东西。 I've not been iOS programming for very long so go easy on me if I'm missing something fundamental!
我已经很长时间没有进行过iOS编程了,所以如果我错过了一些基本的东西,那就轻松吧! Any help would be appreciated greatly.
任何帮助将非常感激。 Even if it's just saying which above approach I should go with and keep trying at.
即使它只是说我应该采用哪种方法并继续尝试。 Thanks!
谢谢!
Edit 编辑
I should probably mention that when I said TableViewController I meant a custom subclass of a TableViewController which uses a FetchedResultsController to populate the cells. 我应该提一下,当我说TableViewController时,我的意思是TableViewController的自定义子类,它使用FetchedResultsController来填充单元格。
If you're going to have a modal segue to a new view controller (or a tab bar controller with tabs that point to navigation controllers), and you want that view controller to have a navigation bar, then you should select the view controller you want to present modally, embed it in a navigation controller (Editor->Embed In->Navigation Controller), and then modally segue to the navigation controller. 如果您要对新的视图控制器(或带有指向导航控制器的选项卡的标签栏控制器)进行模态转换,并且您希望该视图控制器具有导航栏,那么您应该选择视图控制器想要以模态方式呈现,将其嵌入导航控制器(Editor-> Embed In-> Navigation Controller),然后以模态方式转换到导航控制器。 Same concept applies for your tab bar controller except they will be relationship segues.
相同的概念适用于您的标签栏控制器,除了它们将是关系segues。
You should add a navigation bar to a UIViewController (not a table view controller), then add the table view, and to that table view add a search bar and a cell. 您应该向UIViewController(而不是表视图控制器)添加导航栏,然后添加表视图,并向该表视图添加搜索栏和单元格。 I've tested this, and it works fine.
我测试了这个,它工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.