Ios 在segue indexath期间在tableview中传递变量

Ios 在segue indexath期间在tableview中传递变量,ios,swift,uitableview,uistoryboardsegue,Ios,Swift,Uitableview,Uistoryboardsegue,我正在尝试将数据从tableview转移到视图控制器。到目前为止,我能够移动单元格中显示的数据,但由于某些原因,我无法使用变量 以下是已经起作用的内容 //Prepare for Segue destination.titleSegue = (cell?.textLabel?.text!)! destination.priceSegue = (cell?.detailTextLabel?.text!)! destination.imageSegue = (cell?.imageView?.ima

我正在尝试将数据从tableview转移到视图控制器。到目前为止,我能够移动单元格中显示的数据,但由于某些原因,我无法使用变量

以下是已经起作用的内容

//Prepare for Segue
destination.titleSegue = (cell?.textLabel?.text!)!
destination.priceSegue = (cell?.detailTextLabel?.text!)!
destination.imageSegue = (cell?.imageView?.image!)!
所有这些数据都会传输到第二个视图

现在,我将向您展示我的
cellforrowatinexpath

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
}

如果您返回到我的
prepare for segue
我需要调用什么来解析
cellforrowatinexpath
中的“descriptionText”变量,以便将数据移到第二个视图控制器?

正如@vadian所说,在您的prepareforsgue方法中,您可以像这样访问tableView selected row indexPath

let indexPath = tableView.indexPathForSelectedRow

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

正如@vadian所说,在prepareforsgue方法中,您可以像下面这样访问tableView选定行

let indexPath = tableView.indexPathForSelectedRow

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

您在哪里调用您的
performsgue
代码?一如既往,不要从视图(单元格)获取数据,而是从模型(
userList
)获取数据。根据执行顺序的方式(直接或通过
didSelect…
),您需要通过
sender
参数中的单元格或通过
tableView.indexPathForSelectedRow
在哪里调用
performsgue
代码,在
prepareforsgue
中获取索引路径,不要从视图(单元格)获取数据,而是从模型(
userList
)获取数据。根据执行顺序的方式(直接或通过
didSelect…
),您需要通过
sender
参数中的单元格或通过
tableView.indexPathForSelectedRow
获取
prepareForSegue
中的索引路径