maxsokolov / TableKit

Type-safe declarative table views.
MIT License
706 stars 74 forks source link

willDisplayHeaderView and willDisplayFooterView #83

Closed sushant-here closed 6 years ago

sushant-here commented 6 years ago

Hi, I noticed that there is no way to get callbacks for willDisplayHeaderView and willDisplayFooterView. Is there any plans to add this and/or suggestion on how I can access those?

Thanks, Sushant

maxsokolov commented 6 years ago

Hey @sushant40

Sorry for late response. I don't have plans to add method that you have mentioned. But there is an easy way to support them.

final class MyTableDirector: TableDirector {

    func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) 
    {
        invoke(action: .custom("my_event"), cell: nil, indexPath: indexPath)
    }
}

and then catch your event with a row action.

gurgeous commented 4 years ago

Thanks for creating such a great library, much appreciated!

I am commenting on this ancient issue to leave a hint for anyone else trying to implement this callback. The suggested fix is a difficult one - I don't think you can easily use invoke for willDisplayFooterView because it's a section thing, not a row action. If I'm understanding things correctly, you'd have to create a fake indexPath and add your handler to every row.

You'll have better luck just doing your work directly in a TableDirector subclass, or calling back into some other class via a custom delegate.

maxsokolov commented 4 years ago

Hey @gurgeous, thank you for the comment!

You are right. Suggested solution is not the best one. And agree with you, something like this could work better.

final class MyTableDirector: TableDirector {

    var onWillDisplayFooterView: ((_ section: Int) -> ())?

    func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) {
        onWillDisplayFooterView?(section)
    }
}

tableDirector.onWillDisplayFooterView = { [weak self] section in
}