Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add possibility to react on will display header and footer #97

Closed
wants to merge 1 commit into from

Conversation

rad3ks
Copy link

@rad3ks rad3ks commented Nov 25, 2016

As reported in #78 I decided to make small PR with possibility to quickly access two methods of UITableViewDelegate:

  • tableView(_:, willDisplayHeaderView:, forSection:)
  • tableView(_:, willDisplayFooterView:, forSection:)

The reason we need to have the simplest possibility to access those method is that UIKit somehow overrides header view appearance (for UITableViewHeaderFooterVIew) and those two methods can be used for configuring header/footer correctly.

The solution here is to provide two closures:

  • dataSource.willDisplayHeader: ((UIView, Int) -> Void)?
  • dataSource.willDisplayFooter: ((UIView, Int) -> Void)?

I wish we could have better architecture for that than just a properties with closures, but this solution fulfills two most important requirements:

  • provides expected feature
  • don't introduce any breaking change into Static

@dmiluski
Copy link
Contributor

dmiluski commented Oct 4, 2017

Coming in way late to this PR, but what is it's use here? Tracking? Animations? Resizing?

@txaiwieser
Copy link
Contributor

I would really like to access scrollViewDidScroll: its not possible to make this generic?

@dmiluski
Copy link
Contributor

dmiluski commented Nov 21, 2017

@txaiwieser access scrollViewDidScroll: ? Oftentimes, if there are several parties involved, I steer clear of delegate methods unless I for sure own that delegate.

In your case, could you leverage an observer:

// Add an observer (be sure to remove in deinit or viewWillDisappear based on your use case)
tableView.addObserver(self, forKeyPath: "contentOffset", options: [NSKeyValueObservingOptions.new, NSKeyValueObservingOptions.old], context: &contentOffsetContext)

    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        if context == &contentOffsetContext, let offsetValue = change?[.newKey] as? NSValue {
            let offset = offsetValue.cgPointValue
           // Handle offset Changes as you wish.
        }
    }

@jaredegan
Copy link
Contributor

I believe my PR solves this in the best way: #119

You don't want to need to create a bunch of closures for each message in UIScrollViewDelegate or UITableViewDelegate. And you don't want to need to update them with iOS version updates as new ones get added or existing ones get deprecated.

@factotvm factotvm closed this Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants