【发布时间】:2017-04-09 22:19:45
【问题描述】:
tableview 的选定行(.checkmark)值(字符串)保存在 sqlite DB 中,并且必须使用相同的值重新加载 tableview,同时显示复选标记。下面给出的代码sn-p
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print("selected \(arr[indexPath.row])")
if let cell = medTable.cellForRowAtIndexPath(indexPath) {
if cell.selected {
cell.accessoryType = .Checkmark
}
}
if let selectedrows = tableView.indexPathsForSelectedRows {
print("didDeselectRowAtIndexPath selected rows:\(selectedrows)")
let objRegisterModel: RegisterModel = RegisterModel()
medicationFor = "\(selectedrows)"
objRegisterModel.MedicationFor = medicationFor;
let splitString = objRegisterModel.MedicationFor.componentsSeparatedByString(",")
print("getSelectedrowsValues", splitString)
}
}
func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
print("deselected \(arr[indexPath.row])")
if let cell = medTable.cellForRowAtIndexPath(indexPath) {
cell.accessoryType = .None
}
if let sr = medTable.indexPathsForSelectedRows {
print("didDeselectRowAtIndexPath selected rows:\(sr)")
}
}
在重新加载 tableview 时,显示值但不显示复选标记
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = medTable.dequeueReusableCellWithIdentifier(intervalCellIdentifier, forIndexPath: indexPath) as UITableViewCell
cell.accessoryType = .None
cell.textLabel?.text = arr[indexPath.row]
let objRegisterModel: RegisterModel = RegisterModelManager.getDBInstance().getRegisterDataByCurrentMedID(uid)
if objRegisterModel != "" {
medicationFor = objRegisterModel.MedicationFor
}
return cell
}
sqliteDB中保存的值如下所示
**[<NSIndexPath: 0xc000000000200016> {length = 2, path = 0 - 1}]**
【问题讨论】:
-
向我们展示您的 tableView(tableView:UITableView,numberOfRowsInSection section:Int) 方法。
-
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return arr.count }
-
arr 数组中存储的值是什么?
-
@RajeshM 以下任何解决方案对您有帮助吗?
标签: ios swift sqlite uitableview