[英]Not able to jump from tableViewCell to another viewController using segue
[英]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.