gpt4 book ai didi

ios - 从 customCell 访问 IBOutlet 到 ViewController

转载 作者:行者123 更新时间:2023-11-28 08:00:33 25 4
gpt4 key购买 nike

我在 tableView 单元格中有一个 collectionView,我想调用 collectionView outlet 以通过重新加载它来更新我的 UI。我尝试了不同的方法,但因为零而崩溃。无论如何我可以做到这一点吗?

class CustomTableViewCell: UITableViewCell {
@IBOutlet weak var collectionView: UICollectionView!
}

class ViewController: UIViewController {

@IBOutlet weak var tableView: UITableView!

let identifier = "cell"

var data = [CKRecord]()

var sections = [customCollectionModel]()

override func viewDidLoad() {
super.viewDidLoad()
sections = customCollectionModel.createSectionsArray()
fetchDataFromCloud()
}

func fetchDataFromCloud() {
books = [CKRecord]()
books.removeAll()
// Reload CollectionView here

let container = CKContainer.default()
let publicDatabase = container.publicCloudDatabase
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: "Book", predicate: predicate)
query.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]

let operation = CKQueryOperation(query: query)
operation.desiredKeys = ["image"]
operation.queuePriority = .veryHigh
operation.resultsLimit = 25
operation.recordFetchedBlock = { (record) -> Void in
self.data.append(record)
}
operation.queryCompletionBlock = { (cursor, error) -> Void in
if let error = error {
print("Download failed \(error.localizedDescription)")
return
}

print("Download Successful")

OperationQueue.main.addOperation {
// reload collectionView here
}
}
operation.qualityOfService = .userInteractive

publicDatabase.add(operation)
}

最佳答案

当你像这样构造一个 View Controller 时:

var viewController = ViewController() 

socket 尚未连接(并且为零)——它们在 View 加载时连接,然后调用 viewDidLoad。在此函数中(或之后的任何时间),outlets 不会为 nil。

关于ios - 从 customCell 访问 IBOutlet 到 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46778061/

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