在 segue IndexPath 期间在 tableview 中传递变量
Pass variable in tableview during segue IndexPath
我正在尝试将数据从我的 tableview 转移到视图控制器。到目前为止,我能够移动显示在单元格中的数据,但由于某种原因我无法使用变量。
这是已经起作用的
//Prepare for Segue
destination.titleSegue = (cell?.textLabel?.text!)!
destination.priceSegue = (cell?.detailTextLabel?.text!)!
destination.imageSegue = (cell?.imageView?.image!)!
所有这些数据都被传输到第二个视图。
现在,我将向您展示我的 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
}
如果你回到我的 prepare for segue
,我需要调用什么来解析 CellForRowAtIndexPath
中的 "descriptionText" 变量,以便将数据移至第二个视图控制器?
正如@vadian 所说,在您的 prepareForSegue 方法中,您可以像这样访问 tableView 选定的行 indexPath
let indexPath = tableView.indexPathForSelectedRow
let descriptionText = self.userList[indexPath.row].description
我正在尝试将数据从我的 tableview 转移到视图控制器。到目前为止,我能够移动显示在单元格中的数据,但由于某种原因我无法使用变量。
这是已经起作用的
//Prepare for Segue
destination.titleSegue = (cell?.textLabel?.text!)!
destination.priceSegue = (cell?.detailTextLabel?.text!)!
destination.imageSegue = (cell?.imageView?.image!)!
所有这些数据都被传输到第二个视图。
现在,我将向您展示我的 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
}
如果你回到我的 prepare for segue
,我需要调用什么来解析 CellForRowAtIndexPath
中的 "descriptionText" 变量,以便将数据移至第二个视图控制器?
正如@vadian 所说,在您的 prepareForSegue 方法中,您可以像这样访问 tableView 选定的行 indexPath
let indexPath = tableView.indexPathForSelectedRow
let descriptionText = self.userList[indexPath.row].description