我最近启动了Xcode,按照一个例子,我做了一个"didSelectRowAt",从我决定的图像转到我想要的视图。这很好,但现在我想转到不同的故事板,而不是使用我的回收视图。我已经敲打了几天了,我似乎真的不知道怎么做。
这是我的VC
.swiftclass 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)
}
}
}
这是我的故事板。
在此处输入图像描述
如您所见,我想根据我从第一个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)
}
}