首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >每次重新加载时,UITableviewCell文本都会在眨眼后消失

每次重新加载时,UITableviewCell文本都会在眨眼后消失
EN

Stack Overflow用户
提问于 2018-05-30 16:22:46
回答 2查看 58关注 0票数 -3

当我试图在没有主线程闭包的情况下重新加载时,Reload不会调用cellForRowAt。这是我的代码:

class UtititySwitcher:NSObject, UITableViewDataSource, UITableViewDelegate {

let utilityTableview = UITableView()


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

}

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

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = UITableViewCell(style: .default, reuseIdentifier: "Mycell")
    cell.textLabel?.text = "hello"
    return cell
}




func Open(loginID:String, view:UIView)
{
    let frm = view.bounds
    let backView = UIView(frame: frm)
    self.utilityTableview.frame = CGRect(x: frm.minX + 10, y: frm.midY - 50, width: frm.width - 20, height: 100)
    self.utilityTableview.backgroundColor = UIColor.white
    self.utilityTableview.delegate = self
    self.utilityTableview.dataSource = self
    backView.addSubview(self.utilityTableview)
    view.addSubview(backView)

    OperationQueue.main.addOperation {
        self.utilityTableview.reloadData()
    }

}

}

EN

回答 2

Stack Overflow用户

发布于 2018-05-30 16:27:50

您还没有为utilityTableview设置委托和数据源,所以这个表视图不会被告知它应该监听谁的消息以及从谁那里获取数据。在类init中,添加

utilityTableview.delegate = self

utilityTableview.dataSource = self

票数 0
EN

Stack Overflow用户

发布于 2018-05-30 16:38:23

我想原因是: OperationQueue没有初始化你可以试试:

let operationQueue = OperationQueue()

operationQueue.main.addOperation {

    self.utilityTableview.reloadData

}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50599763

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档