我有一个viewController,其中有一个tableview,在每个单元格中都有一个collectionView。
我想转到另一个视图(在那里我将有一个后退按钮),所以我尝试使用我的代码,它正在为其他视图工作:
let vc = self.storyboard?.instantiateViewController(withIdentifier: "detail") as! DetailView
vc.name = beachesNames[indexPath.row]
vc.imagak = imagesNames[indexPath.row]
self.navigationController?.pushViewController(vc, animated: true)
但是因为这段代码在TableViewCell中,所以我有一个错误:
“HomeViewCell”类型的值没有成员“storyboard”
有没有其他的参数,我可以使用或其他什么它可以做我的任务?
提前谢谢。
最佳答案
-斯威夫特3
let detailOrderVC = UIViewController()
self.viewController()?.navigationController?.pushViewController(detailOrderVC, animated: true)
-斯威夫特4
在swift 4中,您需要将viewcontroller传递给如下单元格
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath) as! CustomTableViewCell
// some your logic
cell.viewController = self // CustomTableViewCell needs to have viewController member variable
return cell
}
let detailOrderVC = UIViewController()
self.viewController?.navigationController?.pushViewController(detailOrderVC, animated: true)
关于ios - 如何在单元格Swift中使用pushViewController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43475132/