且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在iOS中向TableView添加工具栏

更新时间:2023-09-21 21:25:10

***的解决方案是使用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.