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:
- Sometime data get populated on second click
- Sometime data get populated after 3-5 seconds
- 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)
}
}
didSelectRowAt
being called? Anything you have tried to solve it? – JP Illanes