这两天我一直在努力解决这个问题。
我只想将页脚(自定义单元格)添加到我的表格视图中。
我有一个视图,上面有一些东西(标签、按钮),并且我添加了一个表格视图。
为了拥有一个干净的控制器,对于数据源,我使用一个单独的文件:
class MyDataSource: NSObject, UITableViewDataSource, UITableViewDelegate {
...
}
在我的控制器中我有:
class MyViewController: UIViewController {
@IBOutlet weak var myButton: UIButton!
var myDatasource: MyDataSource!
@IBOutlet weak var myTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
myDatasource = MyDataSource(....)
myTableView.dataSource = myDatasource
// Do any additional setup after loading the view.
}
So, in MyDataSource
我已经添加:
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let footerView = UIView(frame: CGRectMake(0, 0, tableView.frame.size.width, 40))
footerView.backgroundColor = UIColor.blackColor()
return footerView
}
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 40.0
}
并且这段代码没有被调用。
我查看了文档,发现最后两个方法是UITableViewController
并且不属于UITableViewDataSource
.
所以,我的问题是,如何实现这一目标?
Thanks.
C.C.