【发布时间】:2020-06-04 08:07:21
【问题描述】:
我通过在我的 ViewController (AnimalsVC) 中创建一个 UITableViewDiffableDataSource 类,将 UITableViewDiffableDataSource 用于我的 tableview 的数据源。每当我尝试从数据源类中获取 ViewController 的数据数组(或任何其他变量/函数)时,我都会收到此错误:
Instance member 'animalsArray' of type 'AnimalsVC' cannot be used on an instance of nested type 'AnimalsVC.DataSource'
我不确定为什么会收到此错误,因为我的 DataSource 类在我的 ViewController 类中。这是我的代码:
class AnimalsVC: UIViewController {
var animalsArray = []
class DataSource: UITableViewDiffableDataSource<Int, Animal> {
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
let items = animalsArray //<- This is where the error occurs
return true
}
}
}
【问题讨论】:
标签: ios swift uitableview datasource