UITableView Mix of Static and Dynamic Cells? throw error Cannot call value of non-function type 'UITableView!'”

I am trying to create a UI table view that mix Dynamic and Static cell " something like WIFI settings views ".the first section will be static it will hold the text field and labels. the second section will be dynamic it will show the members of the group.
see the screenshot
40%20PM

I have a problem with code it on UItable view methods "“Cannot call value of non-function type ‘UITableView!’” in the following methods
1-tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) → UITableViewCell
2-tableView(_ tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) → CGFloat
3- func tableView(_ tableView: UITableView, indentationLevelForRowAtIndexPath indexPath: NSIndexPath) → Int
4-tableView(_ tableView: UITableView, indentationLevelForRowAtIndexPath indexPath: NSIndexPath) → Int

import UIKit

class CreateGroupTableViewController: UITableViewController {
    // ----------
    // MARK: - Constants
    // ----------
    
    private struct Section
    {
        static let Static = 0
    }
    
    private struct CellId
    {
        static let Dynamic = "DynamicCell"
    }
    
    // ----------
    // MARK: - Lifecycle
    // ----------
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    // ----------
    // MARK: - UITableViewDataSource
    // ----------
    
     func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool
    {
        return false
    }
    
    // ----------
    
     func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool
    {
        return false
    }
    
    // ----------
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        if section == Section.Static {
            // count of your data source items
            return 3
        }
        else {
            return super.tableView(tableView, numberOfRowsInSection: section)
        }
    }
    
    func tableView(_ tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell.EditingStyle
    {
        return .none
    }
    
    // ----------
    
//     func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
//    {
//        if indexPath.section == Section.Static
//        {
//            var cell = tableView.dequeueReusableCell(withIdentifier: CellId.Dynamic)
//
//            if cell == nil {
//                // create dynamic cell from xib or with default style
//                cell = UITableViewCell(style: .value1, reuseIdentifier: CellId.Dynamic)
//            }
//
//            // customize your dynamic cell
//            if let cell = cell
//            {
//                cell.textLabel?.text = "test"
//                cell.detailTextLabel?.text = "\(indexPath.row)"
//
//                return cell
//            }
//        }
//
//        return super.tableView(tableView, cellForRowAtIndexPath: indexPath)
//    }
    
    // ----------
    // MARK: - UITableViewDelegate
    // ----------
    

    
    // ----------
    
//     func tableView(_ tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
//    {
//        if indexPath.section == Section.Static {
//            // custom or calculating height for dynamic cell
//            return 60.0
//        }
//        else {
//            return super.tableView(tableView, heightForRowAtIndexPath: indexPath)
//        }
//    }
    
    // ----------
    
//     func tableView(_ tableView: UITableView, indentationLevelForRowAtIndexPath indexPath: NSIndexPath) -> Int
//    {
//        if indexPath.section == Section.Static {
//            // use only this indentation level for dynamic cell
//            return super.tableView(tableView, indentationLevelForRowAtIndexPath: NSIndexPath(forRow: 0, inSection: Section.Static))
//        }
//        else {
//            return super.tableView(tableView, indentationLevelForRowAtIndexPath: indexPath)
//        }
//    }
//    
    // ----------
}

Static and dynamic cells are determined by the table view, not the section. You’ll need to create two table views. One with static cells corresponding to your 1st section, and another with dynamic cells corresponding to your 2nd section. Hope that helps.

Have fun!

1 Like

thanks for help.sorry for my late reply.I have resolved the issue by using UIContainerView in the 2nd section

hi @a-elnajjar,
Did you resolve your issue? you can do this with one tableView also but instead you will have to set the rows according to the section.

cheers,

This topic was automatically closed after 166 days. New replies are no longer allowed.