如何使用多个TableView单元预制一个segue

时间:2016-01-03 23:40:15

标签: ios swift xcode uitableview segue

我有多个表格视图单元格,我希望它们中的每一个都能预先形成特定的segue。我不知道我会怎么做

我的第一个单元格首先说,第二个单元格名称是第二个。

我尝试从每个单元格中拖动并在我的主题板中创建一个show segue。但是当我选择细胞时没有任何反应。我是否必须编写代码或不确定。我知道我可以使用标识符来预先创建segue,但我不知道该代码必须是什么。我试过这段代码:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("showDetails", sender: tableView)

}

但我似乎无法为每个细胞做到这一点。

我所有的代码都很快。

非常感谢。

1 个答案:

答案 0 :(得分:2)

如果您想为特定单元格设置特定的段,可以检查didSelectRowAtIndexPath中单击的行,然后执行segue。像这样(if-statements只是例子):

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    if (indexPath.row == 0){
        self.performSegueWithIdentifier("showDetails", sender: tableView)
    }
    else if (indexPath.row >= 1 && indexPath.row <= 10){
        self.performSegueWithIdentifier("showAnother", sender: tableView)
    }
    else{
        self.performSegueWithIdentifier("showTheLast", sender: tableView)
    }
}