temre
temre

Reputation: 189

How to pass selected row data to another ViewController

I have a tableview like this

enter image description here

I want to take the link and pass it to another controlview.

Here what i have done

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {


    let linktopass = classes[indexPath.row].valueForKey("link")
    print(linktopass)


    func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        let thirdVC: web = segue.destinationViewController as! web

        thirdVC.link = linktopass as! String

But it does not work.

Here is my print's output.

Optional( http://blablabla )

Upvotes: 0

Views: 776

Answers (1)

Ketan Parmar
Ketan Parmar

Reputation: 27428

If think you forget to performsegue in didSelectRowAtIndexPath.

prepareForSegue is get called before you performsegue. if you are not performing segue then your prepareForSegue will not called.

so, in didSelectRowAtIndexPath, add code like,

  performSegueWithIdentifier("goToNextVC", sender: self) //your segue identifier here
  //goToNextVC is segue identifier set from attribute inspector from storyboard

Make sure you have set segue identifier from attribute inspector.

You can set identifier like,

select segue - click attribute inspector - write identifier in it - press enter

Hope this will help :)

Upvotes: 1

Related Questions