【发布时间】:2017-10-04 16:44:49
【问题描述】:
单击 rightHeaderButtonClicked 方法时,我试图从 MainViewController 导航到其他 ViewController。但是,它不会导航。我已经分享了下面的代码。
Appdelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
fileprivate func createMenuView() {
// create viewController code...
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let mainViewController = storyboard.instantiateViewController(withIdentifier: "MainViewController") as! MainViewController
let menuViewController = storyboard.instantiateViewController(withIdentifier: "MenuViewController") as! MenuViewController
let nvc: UINavigationController = UINavigationController(rootViewController: mainViewController)
menuViewController.mainViewController = nvc
let slideMenuController = ExSlideMenuController(mainViewController:mainViewController, leftMenuViewController: menuViewController)
slideMenuController.automaticallyAdjustsScrollViewInsets = true
slideMenuController.delegate = mainViewController
slideMenuController.removeRightGestures()
self.window?.backgroundColor = UIColor(red: 236.0, green: 238.0, blue: 241.0, alpha: 1.0)
self.window?.rootViewController = slideMenuController
self.window?.makeKeyAndVisible()
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
createMenuView()
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
MainViewController.swift
class MainViewController: UIViewController,SlideMenuControllerDelegate {
@IBOutlet weak var chitsTableView: UITableView!
var mainVc: UIViewController!
override func viewDidLoad() {
super.viewDidLoad()
chitsTableView.register(UINib(nibName: "ChitTableViewCell", bundle: nil), forCellReuseIdentifier: "ChitTableViewCell")
}
override func viewWillAppear(_ animated: Bool) {
self.slideMenuController()?.changeMainViewController(self.allbiddersViewController, close: true)
self.navigationController?.isNavigationBarHidden = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func viewDidAppear(_ animated: Bool) {
self.slideMenuController()?.addLeftGestures()
}
@IBAction func leftHeaderButtonClicked(_ sender: UIBarButtonItem) {
self.slideMenuController()?.openLeft()
}
@IBAction func rightHeaderButtonClicked(_ sender: UIBarButtonItem) {
let chitdetailVc = self.storyboard?.instantiateViewController(withIdentifier: "ChitDetailViewController") as! ChitDetailViewController
self.slideMenuController()?.navigationController?.pushViewController(chitdetailVc, animated: true)
}
}
我无法理解 SlideMenuViewController 的层次结构,并且 viewcontroller 堆栈总是打印 nil。
【问题讨论】:
-
这里没有足够的信息给你答案。 ExSlideMenuController 上面没有代码。这是你写的,还是开源的?
标签: ios swift uinavigationcontroller