首页 > 解决方案 > 从 coredata (Swift) 返回行数

问题描述

我正在尝试将UITableView保存到 coredata 的 a 中的一些图像传递给 a UICollectionView,它不是 coredata 的一部分。

我希望 of 的返回计数numberOfItemsInsection应该UICollectionView等于 的总行数UITableView。如何访问 的行数UITableView

标签: iosswiftxcodeuitableviewuicollectionview

解决方案


您可以访问 tableview numberOfRows 为:

    tableView.numberOfRows(inSection: [//Section No])

您可以从 Coredata 获取 numberOfRows 为:

func getRecordsCount() {
    let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: _entityName)
    do {
        let count = try context.count(for: fetchRequest)
        print(count)
    } catch {
        print(error.localizedDescription)
    }
}

推荐阅读