How to access parent tableview indexpath.section in child tableviewcell


I have a Main Tableview in that cell I have a collectionview and in that cell i have a tableview, I want to access parent tableviewcell in my sub tableview, when user selects a perticular child table i want to access the main tableview indexpath of section.

Now in code I am taking a global Int variable and taking the main section indexPath and trying to access that index but I am getting wrong results:

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.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) });
        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()


I’m not sure it s correct design, but you can use delegate mechanism or use notification kind a
Sorry, but your code is not supposed to work at all. Storing the indexPath into a global variable will not help at all, because the function tableView(_:cellForRowAt:) will be called all the time a cell is to be displayed. This is completele independend from any selection, tapping etc. I would suggest to completly rething the data structures. Also, if I got it right, you are nesting table views inside table views, which also could be very confusing to the user and does not look like a good UI design to me.