1

I had an a problem with this code, this identifier didn't run with me

import UIKit

class RestaurantDetailViewController: UIViewController {


    @IBOutlet var restaurantImageView: UIImageView!
    var restaurantImage = ""

    override func viewDidLoad () {
        super.viewDidLoad ()

        restaurantImageView.image = UIImage(named: restaurantImage)
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "showRestaurantDetail" {
            if let indexPath = tableView.indexPathSelectedRow {
                let destinationController = segue.destinationViewController as! RestaurantDetailViewController
                destinationController.restaurantImage = restaurantImageView[indexPath.row]
            }
        }
    }
}

The error is : Use of unresolved identifier 'tableView'

Looking for a solution. Thanks,

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
user2508528
  • 131
  • 1
  • 3
  • 9

3 Answers3

2

The prepareForSegue method is obviously in the wrong class (copy and paste error?).

It belongs to the Master controller.

vadian
  • 274,689
  • 30
  • 353
  • 361
1

Do you have a tableview in your VIEWCONTROLLER ? If yes then create a IBOOutlet between your class and viewcontroller

-2

you can see this question or this this for reference.

This behavior is called "scope" and is crucial to any programming language. Variables declared inside a method are neither visible outside it nor do they persist when that method has finished running. and in your case for creating tableView variable you have to create an IBOoutlet or you can define it programmatically too you can get more detail from here

and here

Community
  • 1
  • 1
remy boys
  • 2,928
  • 5
  • 36
  • 65