2016-09-09 2 views
0

私はビュービューアからビュービューにデータを取得しようとしています。これまではセルに表示されているデータを移動することができましたが、何らかの理由で変数を取ることができません。ここでsegueの間にテーブルビューで変数を渡すIndexPath

はすでに

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

働いているすべてのデータは、2番目のビューにオーバー転送されますものです。

あなたは、私はデータがに上に移動するために取得するCellForRowAtIndexPathから「descriptionText」変数を解析するために呼び出す必要があるだろうか戻って私のprepare for segueに行けば今、私はあなたに私の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 
} 

が表示されます2番目のビューコントローラ? @vadianが言ったように

+0

ようにtableView選択された行のindexPathへのアクセスを得ることができますか? –

+2

いつものように、**ビュー(セル)からデータを取得せず、モデル( 'userList')からデータを取得しないでください。 segueを(直接または 'didSelect ... 'を介して)実行する方法に応じて、' sender'パラメータのセルか 'tableView.indexPathForSelectedRow'を介して' prepareForSegue'のインデックスパスを取得する必要があります – vadian

答えて

2

、あなたのprepareForSegue方法では、あなたがあなたの `performSegue`コードを呼び出しているこの

let indexPath = tableView.indexPathForSelectedRow 

let descriptionText = self.userList[indexPath.row].description 
関連する問題