【发布时间】:2020-04-19 18:47:14
【问题描述】:
在 myscenario 中,我将 popupVC 文本字段 title 和 descript 值存储到 CoreData 中。曾经,将数据存储到 CoreData 中,然后将数据提取到 UITableView 中。我在editActionsForRowAt 中拥有的每个 Tableview 单元格都有编辑按钮。有一次,用户单击了我正在传递EditpopupVC.task = self.userData[indexPath.row] 的编辑按钮。在 EditpopupVC 中,我收到var task: NSManagedObject? = nil 之类的值。现在,如果用户单击更新按钮修改数据后,我将调用 func update(title: String, descript: String) { } 以获取传递的特定值更新。
编辑按钮单击以将数据从 ListViewController 传递到 EditpopupVC
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let editAction = UITableViewRowAction(style: .default, title: "Edit", handler: { (action, indexPath) in
print("Edit tapped")
let task = self.userData[indexPath.row]
let EditpopupVC = self.storyboard?.instantiateViewController(withIdentifier: "editviewcontroller") as! EditViewController
EditpopupVC.titlename = "Edit"
EditpopupVC.task = self.userData[indexPath.row]
EditpopupVC.modalTransitionStyle = .crossDissolve
EditpopupVC.modalPresentationStyle = .overFullScreen
self.present(EditpopupVC, animated: true, completion: nil)
})
return [editAction]
}
一旦用户修改文本数据然后更新按钮点击调用更新函数
update(title: Titletextfield.text ?? "Empty", descript: Descriptiontextview.text)
我在下面使用的CoreData更新函数
func update(title: String, descript: String) {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let managedObjectContext = appDelegate.persistentContainer.viewContext
task.title = title
task.descript = descript
do {
try managedObjectContext.save()
} catch {
print("Could not save. \(error)")
}
}
EditpopupVC.task = self.userData[indexPath.row] 这一行有助于将数据数组传递给EditpopupVC。
【问题讨论】:
-
你在哪里调用了这个
update(indexPath:方法 -
@Anbu.Karthik 如果用户修改文本并单击更新按钮,我将调用
update(indexPath:。 -
您能否显示代码以及您在表格视图中调用编辑按钮目标的位置
-
@Anbu.Karthik 编辑按钮我放入
editActionsForRowAt内let editAction = UITableViewRowAction(style: .default, title: "Edit", handler: { (action, indexPath) in我打电话给let updateVC = self.storyboard?.instantiateViewController(withIdentifier: "updateVC") -
@Anbu.Karthik 更新问题。请检查!
标签: ios swift uitableview core-data