【问题标题】:Return row count from coredata (Swift)从 coredata (Swift) 返回行数
【发布时间】:2021-08-10 09:50:56
【问题描述】:

我正在尝试将保存到 coredata 的 UITableView 中的一些图像传递给不属于 coredata 的 UICollectionView

我希望 UICollectionViewnumberOfItemsInsection 的返回计数应该等于 UITableView 的总行数。 如何获取UITableView的行数?

【问题讨论】:

  • 您的问题不应该是关于 UITableView 和 UICollectionView,而是关于您用于这些 UI 组件的数据源。所以 UITableView 的行数就是你用作表格视图数据源的数组的count 属性。如果您无权访问要进行比较的数据源,则需要执行计数获取请求,例如,请参阅this question

标签: ios swift xcode uitableview uicollectionview


【解决方案1】:

您可以通过以下方式访问 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)
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-06
    • 2019-12-01
    • 1970-01-01
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多