Как бы я отправил данные из меток из действия строки представления таблицы в контроллер представления?
Я пытаюсь передать данные из ячейки табличного представления в другой контроллер представления посредством действия строки редактирования ячейки табличного представления.
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let edit = UITableViewRowAction(style: .normal, title: "Edit") { (action, indexPath) in
let editViewController = self.storyboard?.instantiateViewController(withIdentifier: "EditViewController") as! EditViewController
self.present(editViewController, animated: true, completion: nil)
let cell = self.recipeList[indexPath.row] as? RecipeTableViewCell
editViewController.nameTextField.text = cell?.recipeNameLabel.text
}
edit.backgroundColor = UIColor(red: 167.0/255.0, green: 204.0/255.0, blue: 181.0/255.0, alpha: 1.0)
return [edit]
}
Это моя клетка для функции акта строки...
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "RecipeCell", for: indexPath) as! RecipeTableViewCell
let recipe = recipeList[indexPath.row]
cell.recipeNameLabel!.text = recipe.name
cell.ratingControl.rating = recipe.rating
}
return cell
}
1 ответ
Вместо того, чтобы передавать каждое значение в вашем целевом VC, попробуйте передать recipe
только объект Затем получите значения из этого объекта и заполните свои элементы управления.
1) создать recipe
объект в вашем EditViewController
var editRecipe : Recipe! // Your Model class
2) Назначить значения
let editViewController = self.storyboard?.instantiateViewController(withIdentifier: "EditViewController") as! EditViewController
editViewController. editRecipe = recipeList[indexPath.row]
self.present(editViewController, animated: true, completion: nil)
3) в ViewDidload
из EditViewController
if editRecipe != nil {
//Fill data in lbls
//lbl_name.text = editRecipe.name
}