访问另一个类[Swift]中的视图控制器方法>> [

问题描述 投票:-1回答:1
通过在ViewController(AnimalsVC)内创建一个UITableViewDiffableDataSource类,我将UITableViewDiffableDataSource用于表视图的数据源。每当我尝试从数据源类内部获取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 } } }

我正在通过在ViewController(AnimalsVC)内创建UITableViewDiffableDataSource类来将UITableViewDiffableDataSource用于表视图的数据源。每当我尝试获取ViewController'...
ios swift uitableview datasource
1个回答
0
投票
我不确定为什么会收到此错误,因为我的DataSource类在ViewController类内。
© www.soinside.com 2019 - 2024. All rights reserved.