0

My Scenario, I am loading JSON data into tableView, whenever I am trying to click tableView custom cell I am getting cell indexPath.row data. Now, I am trying to pass particular cell array data to another viewcontroller. Here, I need to verify below code is correct one or not and also how to get all the values from array and to show on labels in second viewcontroller?

Here below code to passing array value one to another viewcontroller

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    print(self.tableArray[indexPath.row])
    tableView.deselectRow(at: indexPath, animated: true)

    let smallVC = storyboard!.instantiateViewController(withIdentifier: "popupview")  as! PopupViewController
    let item = tableArray[indexPath.row]
    smallVC.array = [item]
    present(smallVC, animated: true, completion: nil)
}

Second ViewController

var array = [Datum]() //Datum decodable root

override func viewDidLoad() {
    super.viewDidLoad()
    print(“DATA: \(array)") //here, i need to get all values and assign label.
}

My Output

DATA: [parseJSON.Datum(catID: "3", catName: "Cars", catParentid: "2", name: “jhon”, year: "3000", fullname: parseJSON.Fullname(firstname: "jio", lastname: "jack"), address: parseJSON.Address(city: "sanfrancisco", state: "california"), ship: parseJSON.Ship(captian: "mojo", time: "12.30.01"))]

2
  • As you get this output, the code is correct. Please add the information which values are supposed to be displayed on which labels. And actually you pass one item, it's not an array. Commented Feb 16, 2019 at 21:06
  • I need to get catID and firstname from inside output array then need to show on label.@vadian Commented Feb 16, 2019 at 21:10

1 Answer 1

1

First of all item is one object of the array. An array is pointless.

smallVC.item = item

and in Second ViewController

var item : Datum!

You get catID and firstname with

let catID = item.catID
let firstname = item.fullname.firstname

It's very easy to figure out the data structure yourself: type item. and see what Xcode suggests.

Sign up to request clarification or add additional context in comments.

2 Comments

wow fentastic. if I want to send this data from second to third view controller what I want to do? second vc present model if I dismiss I am moving my tab index directly to second tab. @vadian
That's another question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.