【问题标题】:table view is not reloading when calling function reloaddata() inside getCArrayList method在 getCArrayList 方法中调用函数 reloaddata() 时不会重新加载表视图
【发布时间】:2018-07-27 05:49:06
【问题描述】:
func getCArrayList(id:String, array:[NSDictionary] ){

    videolist = NSMutableArray()
    videoId = NSMutableArray()
    image = NSMutableArray()

    for i in 0 ..< array.count
    {
        let adict:NSDictionary = array[i] as! NSDictionary

        let bdict:NSDictionary = adict.object(forKey: "snippet") as! NSDictionary
        let cdict:NSDictionary = bdict.object(forKey: "resourceId") as! NSDictionary
        let ddict:NSDictionary = bdict.object(forKey: "thumbnails") as! NSDictionary
        let edict:NSDictionary = ddict.object(forKey: "medium") as! NSDictionary

        self.videolist.add(bdict.object(forKey: "title") as! String)
        self.videoId.add(cdict.object(forKey: "videoId") as! String)
        self.image.add(edict.object(forKey: "url") as! String)

        if videoId[i] as! String == id {
            self.videolist.remove(i)
            self.videoId.remove(i)
            self.image.remove(i)
        }

    }

    self.videotable.reloadData()

}

//calling the fuction:
 getCArrayList(id: videoid, array: didselectarray)

调用此函数 getCArrayList 时,tableview 不会重新加载 该函数在 tableview 方法 didselectrowatindexpath() 中被调用 我哪里错了?任何帮助表示赞赏....

【问题讨论】:

  • 这个方法在主线程中被调用?
  • 与此问题无关,但请停止强制展开值。
  • @ReinierMelian DispatchQueue.main.async { self.videotable.reloadData() } 试过这个但没有改变
  • 检查array.count....它应该大于零......在表格视图中重新加载数据
  • 什么是tableView数组????

标签: ios uitableview swift4 xcode9


【解决方案1】:

请尝试以下方法:

DispatchQueue.main.async {
     self.videotable.reloadData()
}

希望对你有所帮助。

【讨论】:

  • 仍然没有更改表视图没有重新加载
  • 您的 tableview 委托和数据源方法是否被调用?
  • 是的,我已经定义了这些功能,我在 tableview didselectrow() 中调用 GetCArrayList 方法
  • 当代码运行时,它会在 tableview 中显示项目。当用户点击一个单元格时,它应该显示不同的数据,这就是我调用 realoaddata() 方法的原因
  • 你能显示你的 numberOfRowsInSection 和 cellForRowAtIndexPath 的代码吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-25
  • 2021-07-18
相关资源
最近更新 更多