简体   繁体   English

初学者:如何在UITableViewController上添加带按钮的顶栏

[英]Beginner: How to add top bar with buttons on UITableViewController

I'm new to iOS development, I just have UITableViewController in a storyboard. 我是iOS开发的新手,我只是在故事板中有UITableViewController I would like to add a top bar to it with some buttons, how to do that? 我想用一些按钮添加一个顶栏,怎么做?

Notice, I'm using UITabBar that is created by "Storyboard" and my ITableViewController is one item of the UITabBar. 请注意,我正在使用由“Storyboard”创建的UITabBar,而我的ITableViewController是UITabBar的一个项目。

选择你的UITableViewController并转到Editor> Embed In并选择一个导航控制器。

When you create the UITableViewController , do the following: 创建UITableViewController ,请执行以下操作:

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:tableViewController];

and then instead of setting the table view controller as the view, set it to the navigation controller. 然后将其设置为导航控制器,而不是将表视图控制器设置为视图。 Inside your table view controller, you can set the left and right buttons for the navigation bar to UIBarButtonItem s (ask me if you want to know how to do that). 在表视图控制器中,您可以将导航栏的左右按钮设置为UIBarButtonItem (询问我是否想知道如何操作)。

You might look at using the UINavigationController. 您可以查看使用UINavigationController。 https://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UINavigationController_Class/Reference/Reference.html https://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UINavigationController_Class/Reference/Reference.html

If you do not want to use UINavigationController, then what you could do is create a view that has the "top bar" that you are looking for, then add the UITableViewController's view to your new UIView. 如果您不想使用UINavigationController,那么您可以创建一个具有您要查找的“顶部栏”的视图,然后将UITableViewController的视图添加到您的新UIView中。

您需要创建一个UIViewController ,而不是UITableViewController ,然后根据需要放置您想要的元素(在本例中为Table View和UIToolbar)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM