I have a tableview
that has data stored in core data
and when the tableviewCell
is tapped it opens another viewController
with a label
with the data on it. I want to have a textfield
and a button
on that viewController
that when the button
is tapped it updates the tableviewCell
data and saves in core data
.
Here is some code when I pass the data over Main View Controller
:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
var name2 = String()
tableView.deselectRow(at: indexPath, animated: true)
let name = itemName[indexPath.row]
name2 = (name.value(forKey: "title") as? String)!
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let secondVC = storyboard.instantiateViewController(withIdentifier: "secondView") as! SecondViewController
secondVC.name = name2
self.present(secondVC, animated: true, completion: nil)
}
Here is in the other view controller
var name = ""
override func viewDidLoad() {
super.viewDidLoad()
nameLabel.text = name
}
Now all I need is to be able to edit one of those tableviewCells
from the second view controller
and send it into the tableview
in the first and update core data
.
我建议您将第二个视图控制器中的数据保存到核心数据中,并在第一个视图控制器中将其获取并显示在表中。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.