courseData是一个struct对象数组。每个对象有9个字符串变量(holeNumber,Par,SI等)。单元格填充正常,但是当您单击一行时,我试图获取一个详细视图控制器,以使用与该行相关的变量courseImage填充图像视图。 显示完整代码。 courseImage变量仍然显示为nil。
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return courseData.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Hole") as UITableViewCell
let item = courseData[indexPath.row]
let holeLabel = cell.viewWithTag(1) as UILabel
holeLabel.text = item.holeNumber
let parLabel = cell.viewWithTag(2) as UILabel
parLabel.text = item.par
let siLabel = cell.viewWithTag(3) as UILabel
siLabel.text = item.SI
let wyLabel = cell.viewWithTag(4) as UILabel
wyLabel.text = item.whiteYards
let yyLabel = cell.viewWithTag(5) as UILabel
yyLabel.text = item.yellowYards
let ryLabel = cell.viewWithTag(6) as UILabel
ryLabel.text = item.redYards
let photo = item.image
let placeholder = cell.viewWithTag(7) as UIImageView
placeholder.image = UIImage(named: photo)
return cell
}
func tableView(tableView: UITableView, didselectRowAtIndexPath indexPath: NSIndexPath) {
let courseSection = courseData[tableView.indexPathForSelectedRow()!.row]
var tipPic = courseSection.plan
var courseImage : UIImage = UIImage(named: tipPic)!
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var destViewController : DetailViewController = segue.destinationViewController as DetailViewController
if (segue.identifier == "courseTip") {
destViewController.receivedPic = courseImage
}
答案 0 :(得分:2)
这是因为您在didDeselect委托方法中添加代码,这意味着当前没有选定的行。
我相信你的意思是在你的didSelect活动中这样做。