【发布时间】:2020-05-22 06:14:16
【问题描述】:
我已经在我的项目中实现了 UITableView Diffable Datasource。它在 IOS 13 中运行良好。 当我在 iOS 13 版本以下运行此应用程序时,它会警告我它仅在 ios 13 上可用。所以我正在尝试为低于 iOS 13 的版本实现 UITableView。
UITableView 代码已完成,但我在 iOS 13 上遇到了这个问题。
@available(iOS 13.0, *)
typealias UserDataSource = UITableViewDiffableDataSource<TblSection, YoutubeVideoModel>
@available(iOS 13.0, *)
typealias UserSnapshot = NSDiffableDataSourceSnapshot<TblSection, YoutubeVideoModel>
这里,我声明数据源变量
class SearchViewController: UIViewController {
@available(iOS 13.0, *)
var datasource: UserDataSource! //Stored properties cannot be marked potentially unavailable with '@available'
}
初始化数据源和快照
@available(iOS 13.0, *)
func configureDatasource(){
datasource = UITableViewDiffableDataSource<TblSection, YoutubeVideoModel>(tableView: searchTblView, cellProvider: { (tableView, indexPath, modelVideo) -> VideoTableViewCell? in
self.configurationCell(indexPath: indexPath)
})
}
@available(iOS 13.0, *)
func createSnapshot(users: [YoutubeVideoModel]){
var snapshot = UserSnapshot()
snapshot.appendSections([.first])
snapshot.appendItems(users)
datasource.apply(snapshot, animatingDifferences: true)
}
我在声明数据源时遇到此错误,请帮助谢谢。
//Stored properties cannot be marked potentially unavailable with '@available'
我在 collectionview 上也面临同样的问题。
【问题讨论】:
-
你是怎么解决上述问题的??
-
我还没有解决这个问题。如果你发现了什么,请告诉我。
-
@SSS 我得到了解决方案。请检查我的答案。
标签: swift uitableview uicollectionview ios13 uitableviewdiffabledatasource