使用Swift 4更新从Core Data中的UITableViewCell中选择的数据

时间:2019-06-18 10:16:21

标签: xcode8

我将允许用户通过点击表格单元格来编辑数据。用户将选择表单元格,无论他们要修改哪个数据,都会显示一个带有先前选择的数据的newVC“ UpdateDataViewController”。用户可以修改数据

func updateUserInfo(){

  let appDelegate = UIApplication.shared.delegate as? AppDelegate

    let context = appDelegate!.persistentContainer.viewContext

    let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "USER")

    fetchRequest.predicate = NSPredicate(format:"lblName = %@",nameTxtField)
    fetchRequest.predicate = NSPredicate(format: "lblcompany = %@", companyTxtfield)
    fetchRequest.predicate = NSPredicate(format: "tblTech = %@",techTxtField)

    do {
        let test = try context.fetch(fetchRequest)
        let objupdated = test[0] as! NSManagedObject

        objupdated.setValue(nameTxtField, forKey: "name")
        objupdated.setValue(companyTxtfield, forKey: "company")
        objupdated.setValue(techTxtField, forKey: "technology")
        do {
            try context.save()

        } catch {
            print(error)
        }
    } catch {
        print(error)
    }

}


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

   tblView.deselectRow(at: indexPath, animated: true)

  var path = self.tblView.indexPathForSelectedRow


  let vc = FirstScreenVC.init(nibName: "FirstScreenVC", bundle: nil)

    self.navigationController?.popViewController(animated: true)

}

0 个答案:

没有答案