如何修复UITableViewCell segue

时间:2015-08-20 20:47:04

标签: ios xcode swift uitableview cell

我实现了一个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!]
    }

1 个答案:

答案 0 :(得分:0)

您是否尝试过以编程方式调用segue?也许解决方案就是使用tableView(_: UITableView, didSelectRowAtIndexPath: NSIndexPath)来调用你的segue。

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) 
{ 
    performSegueWithIdentifier("first", sender: self.tableView(tableView, cellForRowAtIndexPath: indexPath) ) 
}