Monday, August 3, 2015

How to call tableview controller method within cell class

I was removing cells from table view today with a button in the cell.

So after calling the remove function from the API, here comes the question, how do you refresh the table view's content.

Firstly, create a protocol method in your cell class

protocol BookingTableViewCellDelegate {
    func reloadTableViewData()

}

then 

var delegate: BookingTableViewCellDelegate?

in table view controller

    func reloadTableViewData() {
        println("reloading data")
        self.items.removeAllObjects()
        getBookings()
        self.myBookingTableView.reloadData()
    }

and add 

cell.delegate = self at cellForRowAtIndexPath

then finally, in your cell class:

self.delegate?.reloadTableViewData()

No comments:

Post a Comment