0

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)
        }

    }
17
  • 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. Commented Feb 14, 2018 at 9:48
  • 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. Commented Feb 14, 2018 at 9:49
  • can you show up your classes here? Commented Feb 14, 2018 at 9:50
  • 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? Commented Feb 14, 2018 at 9:50
  • 1
    @user7555810 : It's happening some time in simulators, from xcode 9.0 and above Commented Feb 14, 2018 at 10:24

3 Answers 3

2

It seems that your code does not have any issue

Just run it on real device instead of simulator

Sign up to request clarification or add additional context in comments.

2 Comments

thank you Yes it is working on real device, but we have to find exact solution why not working on simulator.
Yes, you can try it but as i said in comment "It's happening some time in simulators, from xcode 9.0 and above"
0

Do check the Datasource and Delegates of your second tableview.

subfilterTableView.dataSource = self
subfilterTableView.delegate   = self

2 Comments

I already mentioned that I have set datasource & delegate for both table
it seems to me that something is wrong with the delegate of your second tableview, have you tried didset to set the datasource and delegate of second tableview. Try setting the datasource and delegate with didSet in your tableview outlet and lemme know.
0

Put in viewDidLoad():

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

2 Comments

I already mentioned that I have set datasource & delegate for both table
@user7555810 Your question didn't specify where you configure the tableViews, so please be as specific as possible when writing the question, always try to share as much code as you can.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.