BrandonMayU
BrandonMayU

Reputation: 716

Pass variable in tableview during segue IndexPath

I am trying to take data from my tableview over to a view controller. So far I am able to move over the data that is being displayed in the cell but for some reason I can't take the variable with.

Here is what is already working

//Prepare for Segue
destination.titleSegue = (cell?.textLabel?.text!)!
destination.priceSegue = (cell?.detailTextLabel?.text!)!
destination.imageSegue = (cell?.imageView?.image!)!

All that data gets transferred over to the second view.

Now, I will show you my cellForRowAtIndexPath

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = UITableViewCell(style: .Subtitle , reuseIdentifier: cellId)

    cell.backgroundColor = UIColor.clearColor() //Makes colour of cells clear so we can see the background
    cell.textLabel?.text = userList[indexPath.row].title //Shoes Name
    cell.textLabel?.textColor = UIColor.whiteColor() //Sets text colour to white
    cell.detailTextLabel?.text = "$\(userList[indexPath.row].price!)" //Displays price of shoes
    cell.detailTextLabel?.textColor = UIColor.whiteColor() //Sets text colour to white

 //LOOK HERE STACK OVERFLOW*******
 let descriptionText = userList[indexPath.row].description




    let URLString = self.userList[indexPath.row].listingImageURL //Finds URL of profile image

    let URL = NSURL(string:URLString!)! //Converts URL Stirng to NSURL

    cell.imageView?.frame = CGRectMake(10,10,100,100) //Sets frame size for images on tableview TODO

    cell.imageView?.contentMode = .ScaleAspectFit //Sets image to aspect fill for image TODO

    cell.imageView?.hnk_setImageFromURL(URL) //Displays image on table view from Haneke Framework

    return cell
}

If you go back to my prepare for segue what would I need to call to parse the "descriptionText" variable from the CellForRowAtIndexPath to get the data to move over to the second view controller?

Upvotes: 0

Views: 127

Answers (1)

praths
praths

Reputation: 353

as @vadian said, in your prepareForSegue Method, you can get access to tableView selected row indexPath like this

let indexPath = tableView.indexPathForSelectedRow

let descriptionText = self.userList[indexPath.row].description

Upvotes: 2

Related Questions