[英]How to fix UITableViewCell segue
我实现了一个NFXRipple单元格,但是现在这些单元格不会切换到下一个表格视图。 这是我的cellForRowAtIndexPath
:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: NFXRippleCell = NFXRippleCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
cell.textLabel?.text = aSport[indexPath.row].name
cell.backgroundColor = UIColor.whiteColor()
cell.textLabel?.font = UIFont(name: "HelveticaNeue", size: 16)
cell.textLabel?.textColor = UIColor.blackColor()
return cell
}
和我的prepareForSegue
:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let cell = sender as! NFXRippleCellN
let row = tableView.indexPathForCell(cell)?.row
let detail = segue.destinationViewController as! SecondTableViewController
detail.selectedSport = aSport[row!]
}
我该怎么调整? 还是我缺少什么?
更新:这是我的控制器中的代码:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: NFXRippleCell = NFXRippleCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
cell.textLabel?.text = aSportl[indexPath.row].name
cell.textLabel?.text = aSport[indexPath.row].name
cell.backgroundColor = UIColor.clearColor()
cell.textLabel?.font = UIFont(name: "HelveticaNeue-Thin", size: 16)
cell.textLabel?.textColor = UIColor.whiteColor()
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { performSegueWithIdentifier("firstSports", sender: self.tableView(tableView, cellForRowAtIndexPath: indexPath) ) }
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let cell = sender as! NFXRippleCell
let row = tableView.indexPathForCell(cell)?.row
let detail = segue.destinationViewController as! SecondTableViewController
detail.selectedSchool = aSport[row!]
}
您是否尝试以编程方式致电segue? 也许解决方案只是使用tableView(_: UITableView, didSelectRowAtIndexPath: NSIndexPath)
来调用您的segue。
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
performSegueWithIdentifier("first", sender: self.tableView(tableView, cellForRowAtIndexPath: indexPath) )
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.