2015-08-29 60 views
2

我試圖從一個TableViewCell導航到一個詳細的VC指示細胞當前業務的細節。這裏有存根tableiewMethods:如何從自定義TableViewCell再次到另一個ViewController(Swift)

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("YelpTableBusinessCell", forIndexPath: indexPath) as! YelpTableBusinessCell 
    var business:Business = Business(dictionary: businessArray[indexPath.row] as! NSDictionary) 
    cell.business = business 
    return cell 
} 
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    businessToUseTVC = Business(dictionary: businessArray[indexPath.row] as! NSDictionary) 
    performSegueWithIdentifier("businessToDetailVC", sender: view); 

} 
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    if let cell = sender as? YelpTableBusinessCell { 
     if segue.identifier == "businessToDetailVC" { 
      if let ivc = segue.destinationViewController as? AttractionsDetailViewController { 
       ivc.businessToUse = self.businessToUseTVC 
      } 
     } 
    } 

} 

我設置了兩個斷點,一個在prepareForSegue方法,一個在didSelectRowAtIndexPath方法

我初始化businessToUseVTC變量didSelectRowAtIndexPath,但是當我運行應用程序,當我在AttractionsDetailVC,其中包含這段代碼,

func loadYelpInfo() { 
     businessName.text = businessToUse.name 
     let thumbImageViewData = NSData(contentsOfURL: businessToUse.imageURL!) 
     thumbImage.image = UIImage(data: thumbImageViewData!) 
     let reviewImageData = NSData(contentsOfURL: businessToUse.ratingImageURL!) 
     reviewImage.image = UIImage(data: reviewImageData!) 
     categories.text = businessToUse.categories 
     reviews.text = "\(businessToUse.reviewCount!) Reviews" 
     distanceLabel.text = businessToUse.distance 
    } 

代碼休息,說businessToUse,設置裏面DetailsVC,是零。

任何幫助將不勝感激。

+0

'loadYelpInfo()'在哪裏調用,並且是'prepareForSegue(::)'中的賦值完全執行 - 當您在調試器中執行時,是否觸及了它? –

回答

2

首先,確保你從控制器拖動VIEWCONTROLLER,而不是單個單元格。

二,發件人不是YelpTablseBusinessCell類型,我相信這是你的問題。

相關問題