Swift 选择特定UITableViewCell时如何进行推送序列

Swift 选择特定UITableViewCell时如何进行推送序列,swift,uitableview,uistoryboardsegue,Swift,Uitableview,Uistoryboardsegue,我正在开发我的第一个iOS应用程序,也是swift的新学员 一切正常,但我很难弄清楚如何从一个特定的单元切换到第三视图控制器。我有一个IOSUITableView,有三个部分,总共有(44)个单元格。点击时,所有单元格都会切换到一个标题为:showProductDetai的DetailVC,这很好。我遇到的问题是,我只需要在UITableView的第0节第5行中有(1)个特定单元格,就可以转到它自己的ViewController,我在其中命名为:second view controller,而不

我正在开发我的第一个iOS应用程序,也是swift的新学员

一切正常,但我很难弄清楚如何从一个特定的单元切换到第三视图控制器。我有一个IOS
UITableView
,有三个部分,总共有(44)个单元格。点击时,所有单元格都会切换到一个标题为:
showProductDetai
DetailVC
,这很好。我遇到的问题是,我只需要在
UITableView
的第0节第5行中有(1)个特定单元格,就可以转到它自己的
ViewController
,我在其中命名为:
second view controller
,而不是普通的
showProductDetail
VC。是否有一种智能方法可以使
tableView
第0节第5行中的特定单元格在选中时转到第二视图控制器

这是我目前正在使用的代码。我将如何编写代码来进行更改

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "ProductCell", for: indexPath) as! ProductTableViewCell

    // Configure the cell...
    let productLine = productLines[indexPath.section]
    let products = productLine.products
    let product = products[indexPath.row]

    cell.product = product

    return cell
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {

    let productLine = productLines[section]

    return productLine.name
}

// Mark: UITableViewDelegate

var selectedProduct: Product?

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
    let productLine = productLines[indexPath.section]
    let product = productLine.products[indexPath.row]
    selectedProduct = product
    performSegue(withIdentifier: "ShowProductDetail", sender: nil)


}

// Mark: - Navigation

override func prepare(for segue: UIStoryboardSegue, sender: Any?)
{
    if segue.identifier == "ShowProductDetail" {
        let DetailVC = segue.destination as! DetailViewController
        DetailVC.product = selectedProduct

    }
}

看到我在这里做了什么吗?您可以使用
indepath
参数获取用户所接触的部分和行,然后您可以设置编程序列

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
    if ((indexPath.section == 0) && (indexPath.row == 5)) {
        performSegue(withIdentifier: "GoToSecondViewController", sender: nil)
     } else {
        let productLine = productLines[indexPath.section]
        let product = productLine.products[indexPath.row]
        selectedProduct = product
        performSegue(withIdentifier: "ShowProductDetail", sender: nil)
    }
}

看到我在这里做了什么吗?您可以使用
indepath
参数获取用户所接触的部分和行,然后您可以设置编程序列

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
    if ((indexPath.section == 0) && (indexPath.row == 5)) {
        performSegue(withIdentifier: "GoToSecondViewController", sender: nil)
     } else {
        let productLine = productLines[indexPath.section]
        let product = productLine.products[indexPath.row]
        selectedProduct = product
        performSegue(withIdentifier: "ShowProductDetail", sender: nil)
    }
}

为所需的节和行编写序列代码:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    if indexPath.section == 0 && indexPath.row == 5 {
        //Perform Segue
    } else {
        //Rest of the functionality
    }
}
确保在故事板中连接了正确的Sugues并提供了正确的标识符


您不需要编写
prepare
Segue方法

为所需的节和行编写Segue代码:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    if indexPath.section == 0 && indexPath.row == 5 {
        //Perform Segue
    } else {
        //Rest of the functionality
    }
}
确保在故事板中连接了正确的Sugues并提供了正确的标识符


仅当您需要将任何内容传递给第二视图控制器(如将所选产品传递给DetailVC)时,您不需要编写
prepare
Segue方法

。仅当您需要将任何内容传递给第二视图控制器(如将所选产品传递给DetailVC)。