0
votes

I have two tableview on the screen. I have set delegate & datasource for both tableview. Lets have consider one table to show main filters & on click of particular cell/filter i have to reload subfilters in second tableview.

So i tried very simple solutions, didSelectRowAt,

subfilterTableView.reloadData()

Even i have tried by calling on main thread too,

DispatchQueue.main.async { 
    subfilterTableView.reloadData()
}

Still its not reloading the subfilterTableView.

I know this beginUpdates() & endUpdates() method are only for to insert & delete cells still i have reload in between beginUpdates() & endUpdates() it make crash as it is accepted.

I know this is stupid question but i have tried every possible simpler solutions.

Following are the some conditions which i come across:

  1. Sometime data get populated on second click
  2. Sometime data get populated after 3-5 seconds
  3. Data get populated on refresh of tableview too

irony is Data get properly populated on real device

Following is my code:

 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        if tableView.tag == 1 {
            return filters.count
        }
        else{
            return subFilters.count
        }
    }

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

        if tableView.tag == 1 {
            let filter = filters[indexPath.row]
            let cell = tableView.dequeueReusableCell(withIdentifier: "FilterTableViewCell", for: indexPath) as! FilterTableViewCell
            cell.labelFilter.text = filter["filterName"] as? String
            cell.backgroundColor = UIColor.clear
            cell.preservesSuperviewLayoutMargins = false
            cell.separatorInset = UIEdgeInsets.zero
            cell.layoutMargins = UIEdgeInsets.zero
            cell.selectionStyle = .none
            return cell
        }
        else{
            let cell = tableView.dequeueReusableCell(withIdentifier: "SubFilterTableViewCell", for: indexPath) as! SubFilterTableViewCell
            cell.labelSubfilter.text = subFilters[indexPath.row]
            cell.backgroundColor = UIColor.clear
            cell.selectionStyle = .none
            return cell
        }
    }


 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        if tableView.tag == 1 {

            let selectedCell:FilterTableViewCell = tableView.cellForRow(at: indexPath)! as! FilterTableViewCell
            selectedCell.labelFilter.textColor = UIColor.black
            selectedCell.contentView.backgroundColor = UIColor.white
            subFilters = filters[indexPath.row]["subFilterValue"] as! [String]


            self.tableViewSubfilters.reloadData()



//            DispatchQueue.main.async {
//                self.tableViewSubfilters.reloadData()
//            }
//            tableViewSubfilters.performSelector(onMainThread: #selector(self.reloadData), with: nil, waitUntilDone: true)
        }

    }
3
how are you filtering the data, issue might be that data is not filtered and sub table is showing the same data as before reloading.Bista
No man i am doing it correct, Even my cellForRowAtIndexPath is calling perfectly what number of cell i am returning but data is not getting populated instantly, sometime it get populate after 3-4 second where i am not using any timer, not performing another any execution.user7555810
can you show up your classes here?Vandit Mehta
Can you share more of your code? How are the tables initialized, are you setting the correct number of sections & rows? Is didSelectRowAt being called? Anything you have tried to solve it?JP Illanes
@user7555810 : It's happening some time in simulators, from xcode 9.0 and aboveVandit Mehta

3 Answers

2
votes

It seems that your code does not have any issue

Just run it on real device instead of simulator

0
votes

Do check the Datasource and Delegates of your second tableview.

subfilterTableView.dataSource = self
subfilterTableView.delegate   = self
0
votes

Put in viewDidLoad():

func viewDidLoad() {
    tableView.delegate = self
    tableView.datasource = self
}