从customCell访问IBOutlet到ViewController

时间:2017-10-16 19:52:15

标签: ios swift cloudkit

我在tableView单元格中有一个collectionView,我想通过重新加载来调用collectionView出口来更新我的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)
    }

1 个答案:

答案 0 :(得分:0)

构造这样的视图控制器时:

var viewController = ViewController() 

插座尚未连接(并且为零) - 它们在视图加载时连接,然后调用viewDidLoad。在此功能中(或以后任何时间),插座不会是零。