[英]Detect which viewController presented the SideMenu and implement proper functionality for its presentation
I'm using the following pod for my SideMenu functionality. 我将以下Pod用于我的SideMenu功能。 Now, if I opened it from XYZ viewController and selected the row which again opens the XYZ viewController, the page is being pushed, but instead, I want the SideMenu to be dismissed, no to push already presented viewController.
现在,如果我从XYZ viewController中打开它,然后选择再次打开XYZ viewController的行,则页面将被推送,但是我想关闭SideMenu,而不要推送已经显示的viewController。
Here is the UI: 这是用户界面:
And here is my didSelectRow code, which is quite clear: 这是我的didSelectRow代码,非常清楚:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.row {
case 0:
let playerVC = NavigationHelper.shared.getStoryBoard().instantiateViewController(withIdentifier: "mainPage") as? MainViewController
navigationController?.pushViewController(playerVC!, animated: true)
case 1:
let historyVC = NavigationHelper.shared.getStoryBoard().instantiateViewController(withIdentifier: "historyPage") as? BroadcastsHistoryViewController
navigationController?.pushViewController(historyVC!, animated: true)
case 2:
let sendMessageVC = NavigationHelper.shared.getStoryBoard().instantiateViewController(withIdentifier: "messagingPage") as? MessaginViewController
navigationController?.pushViewController(sendMessageVC!, animated: true)
case 3:
let settingsVC = NavigationHelper.shared.getStoryBoard().instantiateViewController(withIdentifier: "settingPage") as? SettingsViewController
navigationController?.pushViewController(settingsVC!, animated: true)
case 4:
let aboutVC = NavigationHelper.shared.getStoryBoard().instantiateViewController(withIdentifier: "aboutPage") as? AboutAppViewController
navigationController?.pushViewController(aboutVC!, animated: true)
default: break
}
}
So far I've tried to detect the topMost viewController
, get the presentingViewController
property, but had no success. 到目前为止,我已经尝试检测
topMost viewController
,获取presentingViewController
属性,但是没有成功。 Can anyone help me handle it in a proper way? 谁能帮助我以正确的方式处理它?
try adding var previousVC: UIViewController?
尝试添加
var previousVC: UIViewController?
to the sideMenu root view controller (lets call it SideMenuVC) 到sideMenu根视图控制器(将其称为SideMenuVC)
then on each view controller form where you will present the side menu from add 然后在每个视图控制器表单上,您将在其中显示添加的侧边菜单
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let nextVC = segue.destination as? SideMenuVC {
nextVC.previousVC = self
}
}
then on the XYZViewController case write 然后在XYZViewController的情况下写
if let vc = previousVC as? XYZViewController{
//dismiss sidemenu
} else {
//instantiate and push ViewController
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.