如何从嵌套的可解码模型中的数组获取numberOfRowsInSection的计数

时间:2019-02-19 09:37:54

标签: ios arrays swift sorting

struct myOrdesItems: Decodable {

    let userFName: String?
    let userLName: String?
    let userOrderPreSerial: String?
    let userOrderSerial: Int?
    let userOrderProductsValue: Int?
    let userOrderOrderedDate: String?
    let payTypeDescEN: String?
    let listUserOrderStatus : [listUserOrderStatus]
    let listUserOrderShipmentVM: [listUserOrderShipmentVM]

}

struct listUserOrderStatus: Decodable {
    let userOrderStatusTitleEN: String?
    let userOrderStatusID: Int?
}

struct listUserOrderShipmentVM: Decodable {
    let userOrderStatusTimeLine: [userOrderStatusTimeLine]
}


struct userOrderStatusTimeLine: Decodable {
    let userOrderStatusID: Int?
}


var myorderArray : [myOrdesItems] = []

public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if tableView.tag == 10 {
        return myorderArray.count
    } else {
        for number in 0..<(myorderArray.count) {
            let value = myorderArray[number].listUserOrderShipmentVM.count

            print(value)
            arrayOfElement.append(value)
        }

        return arrayOfElement.count
    }
}

1 个答案:

答案 0 :(得分:0)

我想这就是您要的

 if tableView.tag == 10 {
        return myorderArray.count
 } else {
    return  myorderArray.flatMap{$0.userOrderShipmentVMArray}.count;
}

编辑

更改

 let listUserOrderShipmentVM: [listUserOrderShipmentVM]

 let userOrderShipmentVMArray: [listUserOrderShipmentVM]