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

tableView(_:viewForHeaderInSection:) delegate method cannot be used #81

Open
shinichy opened this issue Nov 2, 2022 · 2 comments · May be fixed by #82
Open

tableView(_:viewForHeaderInSection:) delegate method cannot be used #81

shinichy opened this issue Nov 2, 2022 · 2 comments · May be fixed by #82
Labels
bug Something isn't working

Comments

@shinichy
Copy link

shinichy commented Nov 2, 2022

Describe the bug
tableView(_:viewForHeaderInSection:) delegate method cannot be used when using tableView.didEndScrollingAnimationPublisher.

To Reproduce

class MyViewController: UIViewController {
    @IBOutlet private weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        tableView.didEndScrollingAnimationPublisher
            .sink { print("didEndScrollingAnimation") }
    }
}

extension MyViewController: UITableViewDelegate {
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        // return my header view
    }
}

MyViewController is configured as a delegate of tableView in a storyboard.

Expected behavior
tableView(_:viewForHeaderInSection:) is called

Device:

  • Device: iPhone 14
  • OS: iOS 16
  • 0.4.1

Additional context
RxCocoa supports this by calling tableView.rx.setDelegate(viewController).

@shinichy shinichy added the bug Something isn't working label Nov 2, 2022
@shinichy shinichy linked a pull request Nov 4, 2022 that will close this issue
@shinichy shinichy changed the title tableView(_:viewForHeaderInSection:) delegate method is not called tableView(_:viewForHeaderInSection:) delegate method cannot be used Nov 4, 2022
@BestiOSDev
Copy link

代理 和 pulisher 只能使用其中的一个. 使用了 publisher 之前scroller.delegate 被重新赋值

@markst
Copy link

markst commented Sep 13, 2023

We had a similar trouble with needing to use indexPathForPreferredFocusedView.
Our solution:

class CollectionView: UICollectionView {
  
  // Subclass of `UICollectionView` provides ability to provide a index path for preferred focus closure.
  // Since we're using `CombineCocoa` we lose the ability to use `UICollectionViewDelegate.indexPathForPreferredFocusedView`
  
  var indexPathForPreferredFocused: (() -> IndexPath?)?
  
  override var preferredFocusEnvironments: [UIFocusEnvironment] {
    let indexPath = indexPathForPreferredFocused?()
    let cell = indexPath.map { self.cellForItem(at: $0) }
    return cell?.map { [$0] } ?? super.preferredFocusEnvironments
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants