【问题标题】:How to preform a segue with mutiple TableView Cells如何使用多个表格视图单元执行 segue
【发布时间】:2016-01-03 23:40:15
【问题描述】:

我有多个表格视图单元格,我希望每个单元格都执行特定的转场。我不知道该怎么做

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

我尝试从每个单元格中拖动并在我的主故事板中制作一个节目转场。但是当我选择单元格时没有任何反应。我必须编写代码还是不确定。我知道我可以使用标识符进行 segue,但我不知道那必须是什么代码。我试过这段代码:

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

}

但我似乎无法为我的每个单元格都这样做。

我所有的代码都在 swift 中。

非常感谢。

【问题讨论】:

    标签: ios swift xcode uitableview segue


    【解决方案1】:

    如果您想为特定单元格设置特定的转场,您可以检查在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)
        }
    }
    

    【讨论】:

    • 谢谢,效果很好。 4 分钟后会给你支票。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多