tableview使用类别->子类别->子子类别这样的数组展开和折叠

时间:2018-12-13 08:20:36

标签: swift

我尝试过使用类别->子类别获得结果,但是当我尝试使用子子类别时,我失败了。

`func numberOfSections(在tableView中:UITableView)-> Int {         返回getPriceList.count     }     func tableView(_ tableView:UITableView,numberOfRowsInSection部分:Int)-> Int {         如果getPriceList [section] .isOpened == true {             返回getPriceList [section] .subService!.count + 1         }其他{             返回1         }     }

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let subCategoryIndex = indexPath.row - 1
    if indexPath.row == 0 {
        let cell = tableView.dequeueReusableCell(withIdentifier: CELL_ID.JF_PRICE_LIST_CELL, for: indexPath) as! PriceListCell
        cell.textLabel?.text = getPriceList[indexPath.section].serviceName
        cell.backgroundColor = #colorLiteral(red: 0.2613176107, green: 0.2559443712, blue: 0.2659199238, alpha: 1)
        return cell
    }else{
        let cell = tableView.dequeueReusableCell(withIdentifier: CELL_ID.JF_PRICE_LIST_CELL, for: indexPath) as! PriceListCell
        cell.textLabel?.text = getPriceList[indexPath.section].subService?[subCategoryIndex].subServiceName
        cell.backgroundColor = #colorLiteral(red: 0.2790801227, green: 0.6332188845, blue: 0.4609255791, alpha: 0.8018487966)
        return cell
    }
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    if indexPath.row == 0{
        if getPriceList[indexPath.section].isOpened == true{
            getPriceList[indexPath.section].isOpened = false
            let sections = IndexSet(integer: indexPath.section)
            tableView.reloadSections(sections, with: .fade)
        }else{
            getPriceList[indexPath.section].isOpened = true
            let sections = IndexSet(integer: indexPath.section)
            tableView.reloadSections(sections, with: .fade)

        }
    }
}`

i want like this

0 个答案:

没有答案