当我试图在没有主线程闭包的情况下重新加载时,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()
}
}
}
发布于 2018-05-30 16:27:50
您还没有为utilityTableview
设置委托和数据源,所以这个表视图不会被告知它应该监听谁的消息以及从谁那里获取数据。在类init中,添加
utilityTableview.delegate = self
和
utilityTableview.dataSource = self
发布于 2018-05-30 16:38:23
我想原因是: OperationQueue没有初始化你可以试试:
let operationQueue = OperationQueue()
operationQueue.main.addOperation {
self.utilityTableview.reloadData
}
https://stackoverflow.com/questions/50599763
复制相似问题