0

I have some cell's (image bellow) created by tab[] I need to segue correct value to another view (moreViewController) on this view I have 'nazwa' 'szerokosc' 'dlugosc' and I need to save to nazwa correct "place" from cell etc have somebody any solution? I search it but I don't find :/

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
    self.performSegue(withIdentifier: "more", sender: tableView)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    let destViewController:moreViewController = segue.destination as! moreViewController

}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return nazwaTab.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! cellTableViewCell
    let nazwa = nazwaTab[indexPath.row]
    let szerokosc = szerokoscTab[indexPath.row]
    let dlugosc = dlugoscTab[indexPath.row]
    cell.nazwaLabel.text = nazwa
    cell.szerokoscLabel.text = szerokosc
    cell.dlugoscLabel.text = dlugosc
    return (cell)
}

IMAGE I CAN't "post images yet "

Bhavin Bhadani
  • 22,224
  • 10
  • 78
  • 108
k0le
  • 40
  • 8

2 Answers2

2

Declare a variable nazwa in MoreViewController and assign a value to it before segueing to it.

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
            let identifier = segue.identifier ?? ""
            switch identifier {
              case "more":
                guard let vc = segue.destination as? MoreViewController else {
                  return
                }
                vc.nazwa = self.clickedNazwa
              default:
                break
            }
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
    self.clickedNazwa = nazwaTab[indexPath.row]        
    self.performSegue(withIdentifier: "more", sender: tableView)

}
MjZac
  • 3,476
  • 1
  • 17
  • 28
  • Have u Idea why I have it as "Optional"? – k0le Feb 17 '17 at 07:40
  • Its good to have optional. If you dont want it as optional, declare `nazwa` variable in `MoreViewController` with `!` at the end of the type. e.g. `var nazwa: String!` – MjZac Feb 17 '17 at 07:42
  • I have "var nazwa:String!" but it's steel optional ;d – k0le Feb 17 '17 at 07:45
  • You can use the `??` operator to safely unwrap it. – MjZac Feb 17 '17 at 07:47
  • ye.. I have another question, when I click 1st time on cell "more" is empty, when I click 2nd time it work, but 1st time no why? – k0le Feb 17 '17 at 07:50
0

You can save a selected row to global variable and use it after call: prepare(for segue: UIStoryboardSegue, sender: Any?)

brianha289
  • 338
  • 1
  • 8