如何在iOS中向TableView添加工具栏 [英] How to add a toolbar to a TableView in iOS

查看:116
本文介绍了如何在iOS中向TableView添加工具栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个简单的notes应用程序,我想在TableView的底部添加一个静态栏。例如,我想添加一个帮助按钮。我怎么能只做我的TableView?

I am building a simple notes application and I want to add a static bar at the bottom of the TableView. For example, I want to add a help button. How can I do this to just my TableView?

到目前为止:

我在故事板中添加了一个工具栏,但这使得它坚持到底最后制作的tableView单元格。我希望它坚持到底。我输入此代码以编程方式执行:

I have added a toolbar through storyboard, but that makes it stick at the end of the last made tableView cell. I want it stuck to the bottom. I entered this code to do programmatically:

@property (strong, nonatomic) IBOutlet UIToolbar *toolbar;

我的tableViewController.h文件中的

in my tableViewController.h file and

[self.view addSubview:_toolbar];
[self.navigationController.view setFrame:self.view.frame];

>方法

谢谢!

推荐答案

最好的解决方案是使用UIViewController而不是UITableViewController。 (上面已经说过了,但是让我给你详细说明。)

The best solution is to use a UIViewController instead of a UITableViewController. (This has been said above, but let me give you the details).

用它的相应XIB创建一个新的UIViewController。在你的新UIViewController视图中,在UITableView中拖动它,调整它的大小,然后在你想要的任何地方拖动你的UIToolbar。

Create a new UIViewController with it's respective XIB. Inside your new UIViewController's view drag in a UITableView, resize it, and drag your UIToolbar wherever you want.

你应该有这样的东西:

黑色边框代表UIViewController的主视图。红色边框代表表格视图。蓝色边框代表您的工具栏。

The black border represents the UIViewController's main view. The red border represents the table view. The blue border represents your toolbar.

然后,让您的UIViewController符合两个协议:UITableViewDelegate和UITableViewDataSource。您将手动实现它的基本方法,例如我们的cellForRowAtIndexPath,numberOfRowsInSection等,但它不会花费你很长时间。

Afterwards, make your UIViewController comply with two protocols: UITableViewDelegate and UITableViewDataSource. You will manually have to implement it's essential methods such us cellForRowAtIndexPath, numberOfRowsInSection, etc, but it shouldn't take you long.

将您的UITableView链接到您的UIViewController。将它的数据源和委托属性链接到视图控制器。

Link your UITableView to your UIViewController. Link it's "data source" and "delegate" properties to the view controller as well.

您将在不到15分钟的时间内完成设置。

You will have your setup ready in less than 15 minutes.

这篇关于如何在iOS中向TableView添加工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆