簡體   English   中英

如何從自定義 TableViewCell 轉到另一個 ViewController (Swift)

[英]How to Segue from Custom TableViewCell to Another ViewController (Swift)

我試圖從 TableViewCell 導航到一個詳細信息 VC,指示有關單元格上當前業務的詳細信息。 下面是存根 tableiewMethods:

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方法中

我在didSelectRowAtIndexPath初始化businessToUseVTC變量,但是當我運行應用程序時,當我在 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
    }

代碼中斷,說在 DetailsVC 中設置的businessToUse為零。

任何幫助將不勝感激。

首先,確保您從 VIEWCONTROLLER 中按住 ctrl 拖動,而不是從單個單元格拖動。

其次,發件人不是YelpTablseBusinessCell類型,我相信這是您的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM