简体   繁体   中英

Passing a proxy data source in Bond5 tableview/collectionview binding

With Bond 4.x it was possible to pass my custom data source when binding a tableview to an ObservableArray in order to implement custom invocations of UICollectionViewDataSource methods (eg viewForSupplementaryElementOfKind ) like this:

viewModel.dataSource.bindTo(collectionView, proxyDataSource: HeaderViewCreator()) { indexPath, dataSource, tableView

This is gone now in Bond5 as trying to use the proxyDataSource parameter causes a compiler error expecting a different argument label in the call.

Unfortunately I could not find a proper section in the migration guide and also I had a hard time understanding the documentation in that regard. BNDTableViewProxyDataSource and friends seem to be gone completely from the codebase.

Thanks for any kind of help!

UITableView and UICollectionView now have properties bnd_delegate and bnd_dataSource of type ProtocolProxy . That type has a property forwardTo that you can set to receive delegate or data source callbacks that are not used by ProtocolProxy (ie Bond).

For example:

class MyViewController: UITableViewDelegate {

  var tableView: UITableView

  func viewDidLoad() {
    super.viewDidLoad()
    tableView.bnd_delegate.forwardTo = self
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM