初学者:如何在 UITableViewController 上添加带有按钮的顶部栏
我是 iOS 开发新手,故事板中只有 UITableViewController
。我想添加一个带有一些按钮的顶部栏,该怎么做?
请注意,我使用的是由“Storyboard”创建的 UITabBar,而我的 ITableViewController 是 UITabBar 的一项。
I'm new to iOS development, I just have UITableViewController
in a storyboard. 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
创建
UITableViewController
时,请执行以下操作:然后不要将表视图控制器设置为视图,而是将其设置为导航控制器。在表视图控制器内,您可以将导航栏的左右按钮设置为 UIBarButtonItem(如果您想知道如何执行此操作,请询问我)。
When you create the
UITableViewController
, do the following: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).选择您的 UITableViewController 并转到 Editor >嵌入并选择导航控制器。
Select your UITableViewController and go Editor > Embed In and choose a navigation controller.
您可能会考虑使用 UINavigationController。
https://developer.apple.com/library /ios/DOCUMENTATION/UIKit/Reference/UINavigationController_Class/Reference/Reference.html
如果你不想使用 UINavigationController,那么你可以可以做的是创建一个具有您正在寻找的“顶栏”的视图,然后将 UITableViewController 的视图添加到您的新 UIView 中。
You might look at using the UINavigationController.
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.
您需要创建一个
UIViewController
,而不是UITableViewController
,然后根据需要放置所需的元素(在本例中为表视图和 UIToolbar)。You need to create an
UIViewController
, not aUITableViewController
, and then place the elements you desire however you want (in this case, a Table View and a UIToolbar).