【发布时间】:2018-11-02 09:59:39
【问题描述】:
所以我有一个嵌入在导航控制器中的 VC,而导航控制器又嵌入到带有另外 2 个容器的父 VC 中。对于所有三个容器,我使用函数(来自 Parent VC)来操作它们以显示它们。
如图所示,当我单击 Voice VC 中的 3 行按钮时,它与 Could not cast value of type 'UINavigationController' (0x1b5614200) to 'Pro.VoiceParentViewController 一起崩溃
如果我只嵌入 Voice Parent VC ..我的后退按钮不再起作用 _ = navigationController?.popToRootViewController(animated: true)
原因
po navigationController -> nil
编辑
class VoiceParentViewController: UIViewController {
@IBOutlet weak var container_voiceVC: UIView!
@IBOutlet weak var container_menuVC: UIView!
@IBOutlet weak var containerSettingsVC: UIView!
@IBOutlet weak var constraint_trailingVoiceContainer: NSLayoutConstraint!
@IBOutlet weak var constraint_leadingVoiceContainer: NSLayoutConstraint!
override func viewDidLoad() {
super.viewDidLoad()
}
func menuTouched() {
constraint_leadingVoiceContainer.constant = self.view.bounds.maxX
constraint_trailingVoiceContainer.constant = 2*self.view.bounds.maxX
UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 1.0, options: .curveEaseInOut, animations: {
self.view.layoutIfNeeded()
}) { (isCompleted) in
}
}
.....
class VoiceViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
@IBAction func action_menu(_ sender: Any) {
(self.parent as! VoiceParentViewController).menuTouched()
}
........
class NewConversationViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var mainTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
@IBAction func backButtonPressed(_ sender: Any) {
_ = navigationController?.popToRootViewController(animated: true)
}
【问题讨论】:
-
请分享您的代码。
-
你到底想要什么?
-
我认为您的容器和子层次结构不清楚。请您分享您的故事板的缩小屏幕截图吗?
-
@AmritTrivedi 我已经编辑了我的问题
标签: ios swift swift3 uinavigationcontroller