我正在尝试从TableViewCell导航到详细VC,指示有关单元格上当前业务的详细信息。这是stub 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
方法
我在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
}
代码断开,说明在DetailsVC中设置的businessToUse
是nil。
非常感谢任何帮助。
答案 0 :(得分:2)
首先,确保从VIEWCONTROLLER中拖动,而不是单个单元格。
其次,发件人不属于YelpTablseBusinessCell
类型,我相信这是您的问题。