【问题标题】:Static member rx cannot be using on instance type UICollectionView静态成员 rx 不能在实例类型 UICollectionView 上使用
【发布时间】:2021-10-14 09:40:29
【问题描述】:

所以我开始学习 rxCocoa,并尝试将其实现到 collectionview 中, 我认为 tableview 没有问题,它应该对 collectionView 做同样的事情 但不知何故出现了这个错误。

那么究竟如何使用 rx bind 呢?以及为什么会出现错误

谢谢

我的视图控制器

final class ViewController: UIViewController {
    var presenter:HomePresenter?
    private lazy var collectionView:UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .vertical
        layout.minimumLineSpacing = 1
        layout.minimumInteritemSpacing = 1
        layout.itemSize = CGSize(width: (view.bounds.width/2)-2, height: 370)
        let collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout)
        collectionView.backgroundColor = .white
        return collectionView
    }()
    override func viewDidLoad() {
        super.viewDidLoad()

// THIS IS WHERE THE ERROR STARTS
        presenter?.getProductList().bind(to: collectionView.rx.items(cellIdentifier: ProductCollectionViewCell.identifier, cellType: ProductCollectionViewCell.self){a,b,c in
            
        }).dispose(by:disposeBag)
     }

}

我的主持人

    func getProductList() -> Observable<[ProductEntity]> {
        return self.interactor.getProductList()
    }

【问题讨论】:

  • 我没有看到static。导致错误的行到底在哪里?
  • 在presenter?.getProductLine,在viewdidload里面
  • 我没有使用任何静态类型,除了单元格标识符,但它通常可以工作

标签: ios swift rx-swift


【解决方案1】:

你的括号放错地方了...

presenter?
    .getProductList()
    .bind(to: collectionView.rx.items(cellIdentifier: ProductCollectionViewCell.identifier, cellType: ProductCollectionViewCell.self)) { a, b, c in // two close parens here

    } // no close paren here
    .disposed(by: disposeBag)

【讨论】:

    猜你喜欢
    • 2016-06-24
    • 1970-01-01
    • 1970-01-01
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    • 2018-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多