ios - didSelectRowAt - performSegue indexPath.row 到具有不同设计的 VC

标签 ios swift xcode uistoryboardsegue

我最近启动了 Xcode,我按照一个例子做了一个“didSelectRowAt”,从我决定的图像转到我想要的 View 。这很好,但现在我想转到不同的 Storyboard而不是使用我的回收 View 。几天来我一直在研究这个问题,但我似乎真的不知道该怎么做。

这是我的 VC.swift

class CategoriesVC: UIViewController, UITableViewDataSource, UITableViewDelegate {



@IBOutlet weak var categoryTable: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()
    categoryTable.dataSource = self
    categoryTable.delegate = self


}

    }
}


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let category = DataService.instance.getCategories()[indexPath.row]
    performSegue(withIdentifier: "ProductsVC", sender: category)
    performSegue(withIdentifier: kitListIdentifier, sender: category)
}


override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let productsVC = segue.destination as? ProductsVC {
        let barBtn = UIBarButtonItem()
        barBtn.title = ""
        navigationItem.backBarButtonItem = barBtn
        assert(sender as? Category != nil)
        productsVC.initProducts(category: sender as! Category)


    }

}

这是我的 Storyboard。

enter image description here

如你所见,我想根据我从第一个 VC 中选择的图像位置转到 KitList。 在这种情况下,位置 0。

enter image description here

你能帮我一些忙吗?

谢谢

最佳答案

你可以试试

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)    {
   let category = DataService.instance.getCategories()[indexPath.row]
   if(indexPath.row == 0)
   {
      performSegue(withIdentifier: kitListIdentifier, sender: category)
   }
   else
   {
       performSegue(withIdentifier: "ProductsVC", sender: category)
   }


}

关于ios - didSelectRowAt - performSegue indexPath.row 到具有不同设计的 VC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49853082/

相关文章:

iphone - 我可以在 XCode 4.3.2 中禁用 "Upgrade debugger from GDB to LLDB"警告吗?

Xcode 8 调试器在输出中显示较少的字符

xcode - 如何在 xcode 9.0 中添加 git 存储库?

ios - UICollisionBehavior - UIView 碰撞的自定义形状

iphone - 停止更新位置后无法获得新位置 - IOS

ios - 如何在 parse.com 中创建角色

ios - 合并两个 UIImages swift 4

swift - Swift 中的键盘文本自动校正高度

swift - 在 Swift 中休眠或延迟 Timer 线程

swift - 符合协议(protocol)——一次又一次地添加协议(protocol) stub 并不能修复错误