ios - 如何使用字典中分组结构中的数据填充 UITableView?

标签 ios swift uitableview dictionary struct

我有以下结构,其中包含解析后的 JSON 数据。

struct callRailData {
var callDate: String
var userDetails = callData()
}

struct callData{
var callerName: String?
var callerNumber: String?
var callerCityName: String?
var callerCountryName: String?
var callerStateName: String?
var callAnsweredState: Bool?
var callDirection: String?
var callDuration: String?
var callRecordingURL: String?
var callRecordingPlayer: String?
var callSource: String?
var callCompanyName: String?
}

我需要在 UITableView 中显示此数据,并以“callDate”作为节标题。所以我将结构分组到这个字典中:

var user = [callRailData]()

var sections = Dictionary<String, [callRailData]>()
sections = Dictionary(grouping: user, by: { $0.callDate }). 

我不知道如何在表格 View 中显示这些数据。如何从“sections”获取 numberOfSections 和 numberOfRowsInSection。 请帮助我是 Swift 和 iOS 开发的初学者。

最佳答案

一般我们使用数组作为tableview的数据源。提供 numberOfRows= 数组计数和数组中的“cellForRow”数据源对象。

关于ios - 如何使用字典中分组结构中的数据填充 UITableView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49028896/

相关文章:

ios - 将数组中的图像嵌入到 Collection View 的单元格中

ios - 是否可以获取 MPMediaItem 的 iTunes Store ID?

iOS7 侧边菜单状态栏颜色过渡。如在 iOS7 Facebook 应用程序中

ios - 从 Swift 3 中的 Dictionary<String, Any> 中获取值

ios - react native 按钮单击移动到另一个屏幕

Swift 中的字符串插值

swift - 如何牵连UICollectionViewCell翻转动画

ios - 如何将底部边框添加到 TableView 部分标题

UITableViewCell 和 heightForRowAtIndexPath 的 iOS 动态高度

iphone - 覆盖默认的 tableview setEditing 行为