I want to pass the data from second ViewController to TableView cell through protocol - ios

This is my ViewController2 from where I need to pass the data.
How do I pass the data?
protocol oppo {
func datapass(Name:String,className:String,rollnumner:String, school:String)
}
class ViewController2: UIViewController {
#IBOutlet weak var txtFldNames: UITextField!
#IBOutlet weak var txtFldClasss: UITextField!
#IBOutlet weak var txtFldRoll: UITextField!
#IBOutlet weak var txtFldSchool: UITextField!
var datatrsfer:oppo!
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func actionAdd(_ sender: UIButton) {
datatrsfer.datapass(Name: txtFldNames.text!, className: txtFldClasss.text!, rollnumner: txtFldRoll.text!, school: txtFldSchool.text!)
}
}
// this is main viewcontoller
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
var dataArry = NSMutableArray()
#IBOutlet weak var tblView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
#IBAction func actionPush(_ sender: UIButton) {
let vc = storyboard?.instantiateViewController(identifier: "ViewController2") as! ViewController2
vc.datatrsfer = self
self.navigationController?.pushViewController(vc, animated: true)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
dataArry.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath) as! TableViewCell
return cell
}
}
class TableViewCell: UITableViewCell,oppo {
#IBOutlet weak var txtFldName: UITextField!
#IBOutlet weak var txtFldClass: UITextField!
#IBOutlet weak var txtFldRoll: UITextField!
#IBOutlet weak var txtFldScholl: UITextField!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func datapass(Name: String, className: String, rollnumner: String, school: String) {
txtFldName.text = Name
txtFldClass.text = className
txtFldRoll.text = rollnumner
txtFldScholl.text = school
}
}

import UIKit
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource,oppo {
let nam = NSMutableArray()
#IBOutlet weak var tblView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
#IBAction func actionPush(_ sender: UIButton) {
let vc = storyboard?.instantiateViewController(identifier: "ViewController2") as! ViewController2
vc.datatrsfer = self
self.navigationController?.pushViewController(vc, animated: true)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return nam.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath) as! TableViewCell
if let dict = nam[indexPath.row] as? NSMutableDictionary {
cell.txtFldName.text = dict["name"] as? String
cell.txtFldClass.text = dict["classname"] as? String
cell.txtFldRoll.text = dict["rollnumber"] as? String
cell.txtFldScholl.text = dict["school"] as? String
}
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 300
}
func datapass(Name: String, className: String, rollnumner: String, school: String) {
let dict = NSMutableDictionary()
dict.setValue(Name, forKey: "name")
dict.setValue(className, forKey: "classname")
dict.setValue(rollnumner, forKey: "rollnumber")
dict.setValue(school, forKey: "school")
nam.add(dict)
tblView.reloadData()
}
}

Related

I m getting 4 times values of same data in tableview cell, so kindly help to pass the data with one value

import UIKit
class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSource, pass {
var array = [String]()
#IBOutlet weak var tblView: UITableView!
#IBOutlet weak var btnPush: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return array.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath) as!TableViewCell
cell.lblName.text = array[indexPath.row]
cell.lblFullName.text = array[indexPath.row]
cell.lblRollno.text = array[indexPath.row]
cell.lblClass.text = array[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 200
}
#IBAction func btnPush(_ sender: UIButton) {
let vc = storyboard?.instantiateViewController(withIdentifier: "SecondVC") as!SecondVC
vc.mac = self
self.navigationController?.pushViewController(vc, animated: true)
}
func Datapass(Name: String, FullName Address: String, Rollno: String, Class: String) {
self.array.append(Name)
self.array.append(Address)
self.array.append(Rollno)
self.array.append(Class)
tblView.reloadData()
}
}
import UIKit
protocol pass {
func Datapass(Name:String, FullName:String, Rollno:String, Class:String)
}
class SecondVC: UIViewController {
#IBOutlet weak var textFldName: UITextField!
#IBOutlet weak var txtFldFullName: UITextField!
#IBOutlet weak var txtFldRollno: UITextField!
#IBOutlet weak var txtFldClass: UITextField!
var mac:pass?
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func btnAdd(sender: UIButton) {
mac?.Datapass(Name: textFldName.text!, FullName: txtFldFullName.text!, Rollno: txtFldRollno.text!, Class: txtFldClass.text!)
self.navigationController?.popViewController(animated: true)
}
}
your adding data to your array the wrong way. your adding 4 parameter
and your array will be like this:
array: 0:name|1:Address|2:Rollno|3:Class
and when your reading this from table every time you map this:
cell.lblName.text = array[0]
cell.lblFullName.text = array[0]
cell.lblRollno.text = array[0]
cell.lblClass.text = array[0]
every time table only reads one element of array for 4 times! you are not changing indexpath.row , it will change it's number after loading 1 cell.
the right way to do this is code below:
struct DbModel{
var name:String
var address:String
var rollno:String
var `class`:String
}
var array :[DbModel] = []
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath) as! TableViewCell
let model = array[indexPath.row]
cell.lblName.text = model.name
cell.lblFullName.text = model.address
cell.lblRollno.text = model.rollno
cell.lblClass.text = model.class
return cell
}
func Datapass(Name: String, FullName Address: String, Rollno: String, Class: String) {
let model = DbModel(name: Name, address: Address, rollno: Rollno, class: Class)
self.array.append(model)
tblView.reloadData()
}

Updating Label in Cell

I have a TableView which rows contain label and two buttons. What I wanna do is that when a user clicks the first button "Set Name", a pop up view comes up in which he can input text from keyboard. After hitting "Set", pop up view is dismissed and label inside a row containing the clicked button changes to the input text. I set the delegates but I cannot make label to change.
TableView:
import UIKit
class SetGame: UIViewController, UITableViewDelegate, UITableViewDataSource
{
var numOfPlayers = Int()
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return numOfPlayers
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
cell.Name.text = "Player \(indexPath.row + 1)"
cell.btn1.tag = indexPath.row
cell.btn2.tag = indexPath.row
return cell
}
override func viewDidLoad()
{
super.viewDidLoad()
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.none
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}
#IBAction func setName(sender: UIButton)
{
let thisVC = storyboard?.instantiateViewController(withIdentifier: "SetName") as! SetName
thisVC.delegate = self
present(thisVC, animated: true, completion: nil)
}
#IBAction func setFingerprint(_ sender: UIButton)
{
}
#IBAction func unwindToSetGame(_ segue: UIStoryboardSegue)
{
print("unwinded to SetGame")
}
#IBOutlet weak var tableView: UITableView!
}
extension SetGame: nameDelegate
{
func named(name: String)
{
let indexP = IndexPath(row: 0, section: 0)
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexP) as! TableViewCell
cell.Name.text = "bkjhvghcjhkv"
//wanted to see if it changes first cell. But doesn't work
}
}
TableViewCell Class:
import UIKit
class TableViewCell: UITableViewCell
{
override func awakeFromNib()
{
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool)
{
super.setSelected(selected, animated: animated)
}
#IBOutlet weak var Name: UILabel!
#IBOutlet weak var btn1: UIButton!
#IBOutlet weak var btn2: UIButton!
}
Pop up View:
import UIKit
protocol nameDelegate
{
func named(name: String)
}
class SetName: UIViewController
{
var delegate: nameDelegate!
override func viewDidLoad()
{
super.viewDidLoad()
window.layer.borderWidth = 1
window.layer.borderColor = UIColor.white.cgColor
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}
#IBAction func closePopUp(_ sender: Any)
{
if input.text != ""
{
delegate.named(name: input.text!)
}
dismiss(animated: true, completion: nil)
}
#IBOutlet weak var input: UITextField!
#IBOutlet weak var window: UIView!
}
Replace this
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexP) as! TableViewCell
with
let cell = tableView.cellForRow(at:indexP) as! TableViewCell

TableView Cell actions

I have a ViewController, with a list of data from a son file. This page run perfectly. On this page are many pub's with prices. And I want to make another scene (SecondViewController). And every time, when I push a pub from the list I want to display on another scene more information about that place. That run, but when I choose a pub the program shows the information about the first pub from the list, and when I choose another he shows the previous pub, which I choose before. And sorry my english is very bad. Please help me :D
Here is my ViewController:
import UIKit
var nev: [String] = []
var cim: [String] = []
var ar: [String] = []
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var myIndex: Int?
#IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
let url = Bundle.main.url(forResource: "pubok", withExtension: "json")
do {
let allContactsData = try Data(contentsOf: url!)
let allContacts = try JSONSerialization.jsonObject(with: allContactsData, options: JSONSerialization.ReadingOptions.allowFragments) as! [String : AnyObject]
if let arrJSON = allContacts["Pubok"] {
for index in 0...arrJSON.count-1 {
let aObject = arrJSON[index] as! [String : AnyObject]
nev.append(aObject["Hely neve"] as! String)
cim.append(aObject["Cím"] as! String)
ar.append(aObject["Legolcsóbb sör"] as! String)
}
}
self.tableView.reloadData()
}
catch {
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return nev.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
cell.nevLabel.text = nev[indexPath.row]
cell.arLabel.text = ar[indexPath.row] + "/0.5l"
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
myIndex = indexPath.row
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let vc = segue.destination as! SecondViewController
vc.myIndex = myIndex
}
}
Here is my SecondViewController:
import UIKit
class SecondViewController: UIViewController {
myIndex: Int?
#IBOutlet weak var secondnevLabel: UILabel!
#IBOutlet weak var secondcimLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
secondnevLabel.text = nev[myIndex!]
secondcimLabel.text = cim[myIndex!]
}
}
And this is the TableViewCell:
import UIKit
class TableViewCell: UITableViewCell {
#IBOutlet weak var nevLabel: UILabel!
#IBOutlet weak var arLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
Instead of having the global variable myIndex, have a local variable in the second view controller. Use prepare(for segue:) in the first view controller to assign the selected row index to that variable.
ViewController:
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
#IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
// etc
}
// Remove didSelectRowAt
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let row = (self.tableView.indexPathForSelectedRow as NSIndexPath?)?.row
let vc = segue.destination as! SecondViewController
vc.myIndex = row
}
SecondViewController:
class SecondViewController: UIViewController {
var myIndex: Int?
#IBOutlet weak var secondnevLabel: UILabel!
#IBOutlet weak var secondcimLabel: UILabel!
// etc

How to pass TableViewCell value into new ViewController in Swift 3.0?

I have this JSON data
move.json
{
"status":"ok",
"movement":
[
{
"refno":"REF 1",
"dtfrom":"2017-13-12"
},
{
"refno":"REF 2",
"dtfrom":"2017-13-13"
},
{
"refno":"REF 3",
"dtfrom":"2017-13-14"
},
]
}
So far, I managed to fetch the value into TableViewCell.
But my goal is to pass the value from ViewController.swift into MoveDetails.swift so the value can be display in MoveDetails.swift
And I have these four swift files. I'm having the problem on ViewController.swift and MoveDetails.swift. I'm not sure how to pass the value into new Controller.
The code as below.
ViewController.swift
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
#IBOutlet weak var tableview: UITableView!
var move: [Move]? = []
override func viewDidLoad() {
super.viewDidLoad()
fetchData()
}
func fetchData() {
let urlRequest = URLRequest(url: URL(string: "http://localhost/move.json")!)
let task = URLSession.shared.dataTask(with: urlRequest) {
(data,response,error)in
if error != nil { return }
self.move = [Move]()
do {
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! [String: AnyObject]
if let msFromJson = json["movement"] as? [[String: AnyObject]] {
for mFromJson in msFromJson {
let ms = Move()
if let refno = mFromJson["refno"] as? String, let dtfrom = mFromJson["dtfrom"] as? String {
ms.refno = refno
ms.dtfrom = dtfrom
}
self.move?.append(ms)
}
}
DispatchQueue.main.async {
self.tableview.reloadData()
}
}
catch let error{ print(error)}
}
task.resume()
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "movementstatusCell", for: indexPath) as! MoveCell
cell.refnoLbl.text = self.move?[indexPath.item].refno
cell.dtfromLbl.text = self.move?[indexPath.item].dtfrom
return cell
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.move?.count ?? 0
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "MoveDetails") as! MoveDetails
let selectedMove = self.move?[indexPath.item]
vc.refnoString = selectedMove.refno
vc.dtfromString= selectedMove.dtfrom
self.navigationController?.pushViewController(vc, animated: true)
}
}
MoveCell.swift
import UIKit
class MoveCell: UITableViewCell {
#IBOutlet weak var dtfromLbl: UILabel!
#IBOutlet weak var refnoLbl: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
Move.swift (NSObject)
import UIKit
class Move: NSObject {
var refno: String?
var dtfrom: String?
}
MoveDetails.swift
import UIKit
class MoveDetails: UIViewController {
#IBOutlet weak var refnoLbl: UILabel!
#IBOutlet weak var dtfromLbl: UILabel!
var refnoString: String!
var dtfromString: String!
override func viewDidLoad() {
super.viewDidLoad()
refnoString = refnoLbl.text
dtfromString = dtfromLbl.text
}
override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() }
}
Appreciate if someone can help. Thanks.
You will just have to set the properties of your MoveDetails view controller. And as a suggestion
Instead of storing refnoString and dtfromString properties in MoveDetails, you could just store one property of type Move:
Cache MoveDetails view controller to reuse it
Implement viewDidAppear to update the MoveDetails outlets
So:
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var detailsVC : MoveDetails?
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if (detailsVC == nil) {
detailsVC = self.storyboard?.instantiateViewController(withIdentifier: "MoveDetails") as! MoveDetails
}
detailsVC.move = self.move?[indexPath.item]
self.navigationController?.pushViewController(detailsVC , animated: true)
}
}
Then, override viewDidAppear in MoveDetails view controller and there you just fill in the values into the text label outlets.
class MoveDetails: UIViewController {
#IBOutlet weak var refnoLbl: UILabel!
#IBOutlet weak var dtfromLbl: UILabel!
var move:Move?
override func func viewDidAppear(_ animated: Bool) {
refnoLbl.text = move?.refno
dtfromLbl.text = move?.dtfrom
}
}
Syntax errors cause because I currently have no Xcode available to do the checking

Pass core data from selected table cell to new view controller

I'm trying to pass data (title, ingredients, steps, image) from the selected table cell to a new view controller. But I don't know how to do that. I got lots of errors, so now I'm starting again. Can anyone help me? I'm new to coding. Thanks:-) My code:
VIEWCONTROLLER.SWIFT
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
#IBOutlet weak var tableView: UITableView!
var recipes = [Recipe]()
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}
override func viewDidAppear(animated: Bool) {
fetchAndSetResults()
tableView.reloadData()
}
func fetchAndSetResults(){
let app = UIApplication.sharedApplication().delegate as! AppDelegate
let context = app.managedObjectContext
let fetchRequest = NSFetchRequest(entityName: "Recipe")
do {
let results = try context.executeFetchRequest(fetchRequest)
self.recipes = results as! [Recipe]
} catch let err as NSError {
print(err.debugDescription)
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCellWithIdentifier("RecipeCell") as? RecipeCell {
let recipe = recipes[indexPath.row]
cell.configureCell(recipe)
return cell
} else {
return RecipeCell()
}
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return recipes.count
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "RecipeDetail") {
//I WANT TO PASS THE DATA FROM THE TABLE CELL TO THE NEW VIEW CONTROLLER (RECIPEDETAILVC)
}
}
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
let app = UIApplication.sharedApplication().delegate as! AppDelegate
let context = app.managedObjectContext
context.deleteObject(recipes[indexPath.row])
app.saveContext()
recipes.removeAtIndex(indexPath.row)
tableView.reloadData()
}
}
}
CREATERECIPE.SWIFT
class CreateRecipeVC: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
#IBOutlet weak var recipeTitle: UITextField!
#IBOutlet weak var recipeIngredients: UITextField!
#IBOutlet weak var recipeSteps: UITextField!
#IBOutlet weak var recipeImage: UIImageView!
#IBOutlet weak var addRecipeBtn: UIButton!
var imagePicker: UIImagePickerController!
override func viewDidLoad() {
super.viewDidLoad()
imagePicker = UIImagePickerController()
imagePicker.delegate = self
recipeImage.layer.cornerRadius = 5.0
recipeImage.clipsToBounds = true
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
imagePicker.dismissViewControllerAnimated(true, completion: nil)
recipeImage.image = image
}
#IBAction func addImage(sender: AnyObject!) {
presentViewController(imagePicker, animated: true, completion: nil)
}
#IBAction func createRecipe(sender: AnyObject!) {
if let title = recipeTitle.text where title != "" {
let app = UIApplication.sharedApplication().delegate as! AppDelegate
let context = app.managedObjectContext
let entity = NSEntityDescription.entityForName("Recipe", inManagedObjectContext: context)!
let recipe = Recipe(entity: entity, insertIntoManagedObjectContext: context)
recipe.title = title
recipe.ingredients = recipeIngredients.text
recipe.steps = recipeSteps.text
recipe.setRecipeImage(recipeImage.image!)
context.insertObject(recipe)
do {
try context.save()
} catch {
print("Could not save recipe")
}
self.navigationController?.popViewControllerAnimated(true)
}
}
}
RECIPEDETAILVC.SWIFT
import UIKit
import CoreData
class RecipeDetailVC: UIViewController {
#IBOutlet weak var recipeImage: UIImageView!
#IBOutlet weak var recipeTitle: UILabel!
#IBOutlet weak var recipeIngredients: UILabel!
#IBOutlet weak var recipeSteps: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
//I WANT TO DISPLAY THE CORE DATA INFORMATION FROM THE TABLE CELL I SELECTED.
}
}
RECIPECELL.SWIFT
class RecipeCell: UITableViewCell {
#IBOutlet weak var recipeTitle: UILabel!
#IBOutlet weak var recipeImage: UIImageView!
func configureCell(recipe: Recipe) {
recipeTitle.text = recipe.title
recipeImage.image = recipe.getRecipeImage()
}
}
You need to track which item the person clicked.
var mySelection: Int?
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.tableView.deselectRowAtIndexPath(indexPath, animated: true)
mySelection = indexPath.row
}
Then, use that when doing the segue.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "RecipeDetail") {
//I WANT TO PASS THE DATA FROM THE TABLE CELL TO THE NEW VIEW CONTROLLER (RECIPEDETAILVC)
let recipeDetailControler = segue.destinationViewController as! RecipeDetailViewController
if let mySelection = mySelection {
let recipe = recipes[mySelection]
// add this function to your
recipeDetailControler.configureRecipeData(recipe)
}
}
}
Add this function to RecipeDetailViewController:
func configureRecipeData(recipe: Recipe) {
// IMPLEMENT ME
}

Resources