【问题标题】:How to fix UITableViewCell segue如何修复 UITableViewCell segue
【发布时间】:2015-11-14 16:13:41
【问题描述】:

我实现了一个 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是否存在? prepareForSegue 是否被调用过?
  • 嗯?我不明白@dmarsi
  • 在你的prepareForSegue函数中你把sender投到NFXRippleCellN,这正常吗?
  • 哦,不,这只是在此处复制和粘贴时打错了@Mindsers
  • @MikeStrong 您是否在情节提要中创建了转场?如果你在prepareForSegue 中设置一个断点,当你选择一个单元格时它会被命中吗?

标签: ios xcode swift uitableview cell


【解决方案1】:

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

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

【讨论】:

  • 该方法中应该包含哪些代码来准备转场?
  • 不是准备而是执行。试试performSegueWithIdentifier()。此方法将调用 segue 和您的 prepareforSegue 方法
  • 使用了以下内容:override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { performSegueWithIdentifier("first", sender: NFXRippleCell()) }
  • @MikeStrong 尝试将NFXRippleCell() 更改为self.tableView(tableView, cellForRowAtIndexPath: indexPath)
  • 在哪里改?
猜你喜欢
  • 2020-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多