gpt4 book ai didi

swift UICollectionView 显示空有时甚至错误标题

转载 作者:行者123 更新时间:2023-11-28 15:40:17 24 4
gpt4 key购买 nike

我有一个 UIcollectionView,它有页眉和页脚,有时一个奇怪的错误只是显示屏幕为空。这很奇怪,因为即使在 View Debugger 上它也显示为空,但 Header 是应用程序上的静态图像,而不是从 API 获取的内容,也没有显示。

控制台也没有给出任何错误方法。我尝试转到另一个 View 并强制执行 reloadData() 但仍然没有显示任何内容。我有什么办法可以更好地调试它或确保它不会发生?

这是 View 调试器的样子:

this is how the view debugger looks like

您可以看到页眉和页脚为空的可重用 View :

you can see the header and footer empty

编辑:

这是使用 RxDataSources 创建补充 View 的方式

 dataSource.supplementaryViewFactory = { (dataSource, collectionView, kind, indexPath) in
switch kind {
case UICollectionElementKindSectionHeader:
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: CellReuseId.contentHeaderCollectionView, for: indexPath ) as! ContentHeaderView
headerView.imageView.image = ImageAssets.contentBanner
let tapGestureRecognizer = UITapGestureRecognizer(target:self, action: #selector(self.showListOfEvents(_:)))
headerView.addGestureRecognizer(tapGestureRecognizer)
return headerView

case UICollectionElementKindSectionFooter:
let footerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: CellReuseId.contentFooterCollectionView, for: indexPath) as! ContentFooterView
footerView.setUpObjects()
//setUp Appropiate label or animation
let showFooter: Bool = !(self.centerActivityIndicator?.isAnimating ?? false)
footerView.setUpAppropiateDependingOnResults(isThereMoreResults: self.isThereMoreResults, showFooter: showFooter)
return footerView
default: break
}
//return default
return UICollectionReusableView()
}

这是获取 API 模型并将它们绑定(bind)到 collectionView 的代码

let results = Observable.of(paginationObserver, offlineObserver).merge()
//calls method that calls DB with the appropiate data
.flatMapLatest { [unowned self] parametersChanged -> Driver<LecturesStateResults> in
//since this is being called again, we make sure to clean out "old cache data" on view model
self.videoObject.lecturesResults.value.removeAll(keepingCapacity: true)
return self.setupLectures().asDriver(onErrorJustReturn: LecturesStateResults.empty)
}

results
//Bind the result observable to the UIcollectionView
//UiCollection view only wants an array not an Observable
.map {
if !$0.results.isEmpty { self.centerActivityIndicator?.stopAnimating()}
return [SectionModel(model: "", items: $0.results)]
}
.bind(to: lectureViewSquare.rx.items(dataSource: dataSource))
.addDisposableTo(disposeBag)

lectureViewSquare.rx.setDelegate(self)
.addDisposableTo(disposeBag)

最佳答案

我在使用相同的 ui 渲染时遇到了同样的问题,但没有使用 RxSwift。

解决问题的代码是

dispatch_async(dispatch_get_main_queue(), ^{
[self.collectionView reloadData];
});

关于swift UICollectionView 显示空有时甚至错误标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43779018/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com