UITableView没有在reloadData

时间:2018-02-14 09:46:17

标签: ios swift uitableview

我在屏幕上有两个tableview。我已经设置了代表和tableview的数据源。让我们考虑一个表格来显示主滤波器&点击特定的单元格/过滤器,我必须在第二个tableview中重新加载子过滤器。

所以我尝试了非常简单的解决方案,didSelectRowAt

subfilterTableView.reloadData()

即使我也尝试过调用主线程,

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

仍然没有重新加载subfilterTableView

  
    

我知道这个beginUpdates()& endUpdates()方法仅用于插入&删除单元格仍然我在beginUpdates()&之间重新加载endUpdates()因为被接受而崩溃。

  

我知道这是一个愚蠢的问题,但我已经尝试了所有可能更简单的解决方案。

以下是我遇到的一些情况:

  1. 有时会在第二次点击时填充数据
  2. 有时数据会在3-5秒后填充
  3. 在刷新tableview时填充数据
  4.   
        

    具有讽刺意味的是数据在真实设备上正确填充

      

    以下是我的代码:

     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 个答案:

答案 0 :(得分:1)

您的代码似乎没有任何问题

只需在真实设备上运行它而不是模拟器

答案 1 :(得分:0)

请检查您的第二个// Create content node from content template var content = contentService.CreateContentFromBlueprint(contentTemplate, "Content Node Name"); // Save and publish to new content node Attempt<Umbraco.Core.Publishing.PublishStatus> publishStatus = contentService.SaveAndPublishWithStatus(content); 的{​​{1}}和Datasource

Delegates

答案 2 :(得分:0)

加入viewDidLoad()

func viewDidLoad() {
    tableView.delegate = self
    tableView.datasource = self
}
相关问题