我最近启动了 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。
如你所见,我想根据我从第一个 VC 中选择的图像位置转到 KitList。 在这种情况下,位置 0。
你能帮我一些忙吗?
谢谢
最佳答案
你可以试试
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/