2

我有一个带有集合视图的表格视图单元格。两者都通过 rxdatasource 绑定,我在加载视图时使用仪器泄漏。关于这可能是什么原因的任何想法?谢谢。

泄漏

图片

主页视图控制器

 let dataSource = RxTableViewSectionedReloadDataSource<HomeSection>(configureCell:  { [weak self] dataSource, tableView, indexPath, item in
            guard let self = self else { return UITableViewCell() }

            switch item {
       ....
            case .homeTrendingItem(let viewModel):
                let cell = (tableView.dequeueReusableCell(withIdentifier: trendingIdentifier, for: indexPath) as? ModelProductsCell)!
                cell.delegate = self
                cell.bind(to: viewModel)
                return cell

            }
        }, titleForHeaderInSection: { dataSource, index in
            let section = dataSource[index]
            return section.title
        })

        output.items
            .bind(to: tableView.rx.items(dataSource: dataSource))
            .disposed(by: rx.disposeBag)

模型产品细胞


func bind(to viewModel: ModelProductsViewModel) {
       let input = ModelProductsViewModel.Input()
       let output = viewModel.transform(input: input)

       output.items
       .bind(to: collectionView.rx.items(cellIdentifier: mainReuseIdentifier, cellType: ProductItemCell.self)) { collectionView, viewModel, cell in
               cell.bind(to: viewModel)
       }.disposed(by: cellDisposeBag)

       collectionView.rx.modelSelected(ProductCellViewModel.self)
           .bind {[weak self] vm in
               self?.delegate?.didTapOnItem(p: vm.product)
       }.disposed(by: cellDisposeBag)

       viewModel.loading.asObservable().bind(to: isLoading).disposed(by: rx.disposeBag)

       viewModel.loading.asDriver().drive(onNext: { [weak self] (isLoading) in
           isLoading ? self?.activityIndicator.startAnimating() : self?.activityIndicator.stopAnimating()
       }).disposed(by: cellDisposeBag)
   }

4

0 回答 0