Ios 8 swift - how to add a footer for a table using a separate data source

Within 2 days I try to solve this. I just want to add a footer (user cell) in my tabular view. I have a view with some things on it (shortcuts, buttons), and I added a table view. To have a clean controller, I use a separate file for the data source:

class MyDataSource: NSObject, UITableViewDataSource, UITableViewDelegate {
 ...   
}

In my controller, I:

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 MyDataSourceI added:

 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
    }

And this piece of code is not called. I looked at the documentation and I found that these last two methods are part UITableViewController, not part UITableViewDataSource.

So my question is: how to achieve this?

Thank.

c.c.

+4
source share
2 answers

, UITableViewDelegate. :

tableView(tableView: UITableView, viewForFooterInSection section: Int)

, .

, : , , . tableFooterView.

+2

Swift 3 ( ):

override func tableView( _ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? 

override func tableView( _ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat 
+4

All Articles