我将the following pod用于我的SideMenu功能。现在,如果我从XYZ viewController中打开它,然后选择再次打开XYZ viewController的行,则页面将被推送,但是,我希望关闭SideMenu,而不是推送已经显示的viewController。
这是用户界面:
这是我的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
}
}
到目前为止,我已经尝试检测topMost viewController
,获得presentingViewController
属性,但是没有成功。谁能帮助我以适当的方式处理它?</ p>
答案 0 :(得分:0)
尝试将func main() {
p1 := Player{Id: 1, Username: "peter", Avatar: "avatar.png", Email: "PRIVATE"}
p2 := Player{Id: 1, Username: "peter", Avatar: "avatar.png", Email: "PRIVATE"}
t := Table{Id: 1, PlayerTop: p1, PlayerBottom: p2}
admin, _ := json.Marshal(t)
public, _ := json.Marshal(t.PublicInfo())
fmt.Println(fmt.Sprintf("For admins: %s", string(admin)))
fmt.Println(fmt.Sprintf("For public: %s", string(public)))
}
/*
Output:
For admins: {"id":1,"playerTop":{"id":1,"username":"peter","email":"PRIVATE","birthdate":"0001-01-01T00:00:00Z","avatar":"avatar.png"},"playerBottom":{"id":1,"username":"peter","email":"PRIVATE","birthdate":"0001-01-01T00:00:00Z","avatar":"avatar.png"}}
For public: {"id":1,"playerBottom":{"avatar":"avatar.png","id":1,"username":"peter"},"playerTop":{"avatar":"avatar.png","id":1,"username":"peter"}}
*/
添加到sideMenu根视图控制器(将其称为SideMenuVC)
然后在每个视图控制器表单上,您将在其中显示add的侧面菜单
var previousVC: UIViewController?
然后在XYZViewController案例中写
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let nextVC = segue.destination as? SideMenuVC {
nextVC.previousVC = self
}
}