[英]Push And Present View Controller
I am using a Navigation Controller as a root View Controller and on starting the app a ViewController VC1 appears which has a button that on pressing (with the help of segue) takes you to VC2 which has a table view and 5 cells, Now I Want to use push instead of Segue or present a modal for going to VC3 from VC2 (on click of cells). 我将导航控制器用作根View Controller,并在启动该应用程序时出现一个ViewController VC1,该按钮上有一个按钮,按下该按钮(借助segue)可将您带到具有表格视图和5个单元格的VC2,使用推式代替Segue或提供一种从VC2转到VC3的方式(在单元格上单击)。
I have used 我用过
let displayVC : ForWebViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ForWebViewController") as! ForWebViewController
self.navigationController?.pushViewController(displayVC, animated: false)
The code has been placed under the action of 1st cell's click but nothing happens. 该代码已放置在第一个单元格单击的作用下,但没有任何反应。
Can anyone help 谁能帮忙
以编程方式添加导航控制器
let navController = UINavigationController.init(rootViewController: VC2)
let displayVC : ForWebViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ForWebViewController") as! ForWebViewController
present(displayVC, animated: true, completion: nil)
or 要么
navigationController?.pushViewController(displayVC, animated: true)
objective C: 目标C:
PulseNavigationController * VC3 =(PulseNavigationController*)navigationcontroller;
[homeNavictrl pushViewController:VC3 animated:YES];
swift: 迅速:
let VC3 = NewViewController()
self.navigationController?.pushViewController(VC3, animated: true)
Use this code and your storyboard ID 使用此代码和您的情节提要ID
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(indexPath.section, indexPath.row)//It will print index and section
let hvc = self.storyboard?.instantiateViewController(withIdentifier: "Your Storyboard ID") as! ForWebViewController//Here replace your class name
self.navigationController?.pushViewController(hvc, animated: true)
}
There might be one of the possible things because of which you are facing the issue. 由于您正面临此问题,可能是其中一种可能。 Do check the below points:
请检查以下几点:
1. Have you set the delegate
of tableView
to VC2
. 1.您是否
tableView
的delegate
设置为VC2
。 You can do it in the storyboard
itself or in viewDidLoad()
of VC2
, write the below code: 您可以在
storyboard
viewDidLoad()
storyboard
本身中或在VC2
viewDidLoad()
中完成此操作,编写以下代码:
self.tableView.delegate = self
2. Check if the navigationController
instance is not nil
in the below code: 2.在以下代码中检查
navigationController
实例是否不为nil
:
self.navigationController?.pushViewController(displayVC, animated: false)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.