Swift 将节数组填充到UITableview节
我有一个JSON数据列表:Swift 将节数组填充到UITableview节,swift,uitableview,Swift,Uitableview,我有一个JSON数据列表: ({ "id" = 1; "name" = "lemon tea"; "date" = 20180820; "daycount" = 1; }) 型号: class OrderItemModal: NSObject { var id: String! var name: String! var date: Date! var daycount: String! } 请阅读以下swift文件: 下载or
({
"id" = 1;
"name" = "lemon tea";
"date" = 20180820;
"daycount" = 1;
})
型号:
class OrderItemModal: NSObject {
var id: String!
var name: String!
var date: Date!
var daycount: String!
}
请阅读以下swift文件:
下载ordermodal.swift:
protocol OrderDownloadProtocol: class {
func itemsDownload(items: Array<Any>)
}
...
let bmsOrders = NSMutableArray()
...
weak var delegate: OrderDownloadProtocol!
let urlPath = "http://localhost/production/api/db_orders.php"
func downloadItems() {
let url = URL(string: urlPath)!
let defaultSession = Foundation.URLSession(configuration: URLSessionConfiguration.default)
...
for i in 0..<jsonResult.count
{
jsonElement = jsonResult[i] as! NSDictionary
let bmsOrder = OrderItemModal()
....
bmsOrders.add(bmsOrder)
....
TableViewCell:
sectionArray[indexPath.section].sectionObjects[indexPath.row] as! OrderItemModal
TableViewTitle:
return sectionArray[section].sectionName
第节中的行数:
sectionArray[section].sectionObjects.count
。。。
让sectionItems=groupItem[indexPath.section]
let items=sectionItems[indexPath.row]
for element in items.sectionObjects {
let item = element as! OrderItemModal
cell.name?.text = item.name
因此,该应用程序现在运行正常从外观上看,它感觉您在func tableView中使用了错误的数据源uTableView:UITableView,cellForRowAt indexPath:indexPath。您正在使用orderItems,它包含您收到的所有数据 正如我从generateDayDict了解到的,您刚刚分离了订单项以计算您的部分。您还应该隔离orderItems,以便将它们作为值推送到各自的字典中,或者以您希望的方式管理数据源,以便行选择正确的模型对象
我会创建一个字典,其中键名作为节,值作为OrderItemModal数组,表示UITableView中的相应行您能为numberOfSections添加代码吗,numberOfRowsInSection以及如何在表视图控制器中存储OrderItemModal实例?我已经更新了上面的代码。感谢您的指导,我已经更新了上面的数组集。
return sectionArray[section].sectionName
sectionArray[section].sectionObjects.count
for element in items.sectionObjects {
let item = element as! OrderItemModal
cell.name?.text = item.name