UITableView有3个部分-直接从函数更新第0行和第0部分
我的UITableView中有3个部分。第一个有一个样式右细节样式,只有一行。第二行和第三行具有自定义样式和动态行 我想在第一节中更新函数中的detailTextLabelUITableView有3个部分-直接从函数更新第0行和第0部分,uitableview,swift,Uitableview,Swift,我的UITableView中有3个部分。第一个有一个样式右细节样式,只有一行。第二行和第三行具有自定义样式和动态行 我想在第一节中更新函数中的detailTextLabel let idx = NSIndexPath(forRow: 0, inSection: 0)! var cell = self.tableView.dequeueReusableCellWithIdentifier("CellServerStatus", forIndexPath: idx) as! UITableViewC
let idx = NSIndexPath(forRow: 0, inSection: 0)!
var cell = self.tableView.dequeueReusableCellWithIdentifier("CellServerStatus", forIndexPath: idx) as! UITableViewCell
cell.detailTextLabel?.text = "Connected"
self.tableView.reloadData()
但标签上什么也没发生。该函数位于主类中
我错了什么
非常感谢
Sven您只更改单元格的标签,然后调用
reloadData()
,它会立即从表的数据源中检索原始值
您需要更改数据源中的值。您所做的不是更新屏幕中tableView的内容,而是修改不在tableView中的单元格 您有两种选择: 直接修改:
let indexPath = NSIndexPath(forRow: 0, inSection: 0)
if let cell = self.tblMain.cellForRowAtIndexPath(indexPath) {
//do your work with cell
}
- 将字符串更新为已连接,然后在表视图上调用
,然后在回调reloadData
中,使用该字符串设置单元格cellforrowatinexpath