如何在子tableviewcell中访问父tableview indexpath.section

时间:2017-12-11 14:04:08

标签: ios swift uitableview

我在该单元格中有一个Main Tableview我有一个集合视图,在该单元格中我有一个tableview,我想在我的子tableview中访问父tableviewcell,当用户选择一个特殊的子表我想访问主tableview indexpath部分。

现在在代码中,我正在使用全局Int变量并使用主要部分indexPath并尝试访问该索引,但结果出错:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let list:[String:Any] = arrOfObjs1[indexPath.row]

    // This is global integer Variable 
    Utilities.shared().sectionInEntityInstance = indexPath.section

    let typeStr:String = list["type"] as! String

    if typeStr == "column" {
        let list1:[Any] = list["list"] as! [Any]
        let item:[String:Any] = list1[indexPath.row] as! [String : Any]

        let info:[String:Any] = item["info"] as! [String : Any]

        let dataTypeId:Int = info["dataTypeId"] as! Int
        if dataTypeId == 4 {

            let cell = tableView.dequeueReusableCell(withIdentifier: "EntityInstanceTextCell")
            cell?.textLabel?.text = info["label"] as? String
            cell?.detailTextLabel?.text = "\(item["value"] ?? "")"
            return cell!
        }

    } else if typeStr == "section" {
        let cell = tableView.dequeueReusableCell(withIdentifier: "EntityInstanceTableViewCell") as! EntityInstanceTableViewCell
        cell.tag = indexPath.section
        print("cellTag:>>> \(cell.tag)")
        var listOfColumns:[Any] = []
        if list["list"] != nil {
            listOfColumns.append(contentsOf: list["list"] as! [Any])
        }

        let list1 = entitiesList
        let listObj:[[String:Any]] = list1[indexPath.section] as! [[String:Any]]
        cell.loadTabs(tabs: listObj, index: cell.tag)
        Utilities.shared().tabsDataArray.removeAll()
        Utilities.shared().tabsDataArray.append(contentsOf: listOfColumns)

        return cell
    } else if typeStr == "field" {
        let cell = tableView.dequeueReusableCell(withIdentifier: "CustomLabelTableViewCell") as! CustomLabelTableViewCell
        let list1 = entitiesList

        let listObj:[[String:Any]] = list1[indexPath.section] as! [[String:Any]]

        let predicateData = NSPredicate(format: "paramId = %@", (list["paramId"] as? String)!)

        let filteredArray:[Any] = (listObj.filter { predicateData.evaluate(with: $0) });
        print(filteredArray)
        let filteredObj:[String:Any] = filteredArray.first as! [String : Any]
        let info:[String:Any] = filteredObj["info"] as! [String:Any]
        //let str = info["label"] as! String
        cell.titleLbl.text = info["label"] as? String
        // cell.titleLbl.text = "\(str):"
        cell.detailedLbl.text = (filteredObj["value"] as! String)
        return cell
    }
    return UITableViewCell()
}

0 个答案:

没有答案