Chr*_*ell 3 xcode uitableview checkmark ios swift
我正在构建一个主细节应用程序.我有一个部分视图控制器(VC),它是主VC的子代.单击VC部分中的行会显示用户完成所需信息的不同详细信息VC.一旦详细VC中的信息完成,我希望在VC行的相关部分中显示复选标记.FYI selectedProject是核心数据对象.
我在详细VC viewWillDisappear中调用通知来刷新VC部分.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
let detailCase: String = selectedProject!.section![indexPath.row]
configureCell(cell, withSectionName: detailCase)
print("location complete is \(selectedProject!.completeLocation)")
print("electricity complete is \(selectedProject!.completeElectricity)"
print(cell.textLabel!.text!)
print(cell.accessoryType.rawValue)
return cell
}
func configureCell(_ cell: UITableViewCell, withSectionName sectionName: String) {
switch sectionName {
case "Project Details" :
cell.accessoryType = .checkmark
case "Location" :
if selectedProject?.completeLocation == true {
cell.accessoryType = .checkmark
}
case "Electricity Use" :
if selectedProject?.completeElectricity == true {
cell.accessoryType = .checkmark
}
default :
cell.accessoryType = .none
}
cell.textLabel!.text = sectionName
}
func refreshTable(notification: Notification) -> Void {
print("Notification ran")
self.tableView.reloadData()
}
Run Code Online (Sandbox Code Playgroud)
安慰:
通知跑了
位置完整是真的
电力完成是真的
项目细节
3
位置完整是真的
电力完成是真的
地点
3
位置完整是真的
电力完成是真的
电力使用
3
3's = .checkmark
因此看起来cellForRowAt确切地知道它应该做什么但是表格不容易显示复选标记.相反,您必须单击返回主VC然后转发到VC部分才能显示复选标记,或者您必须单击VC部分中的不同行,并且随机显示复选标记.
我试过在dispatchqueue.main.async中调用reloadData没有运气.我尝试再次在进程中的不同点调用reloadData而没有成功.我已经尝试调用tableView.beginUpdates/.endUpdates和reloadSectionData,再次没有成功获取要显示的复选标记.
如果我以编程方式连续提示VC viewWilDisappear和viewWillAppear部分,则一旦选择了VC部分中的不同行,就会出现复选标记.它"似乎"像reloadData()没有提示完全重载tableView.
FYI附件项目在故事板中设置为.none.
dyl*_*ion 12
需要在主队列上调用UI更新.试试这个:
DispatchQueue.main.async {
self.tableView.reloadData()
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5503 次 |
| 最近记录: |