0
我試圖從Mainviewcontroller導航到其他視圖控制器,當點擊rightHeaderButtonClicked method.But,它不會導航。我已經分享了下面的代碼。如何使用SlideMenuViewcontroller從Mainviewcontroller導航到另一個視圖控制器
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的層次結構和視圖 - 控制堆棧版畫始終爲零。
這裏沒有足夠的信息給你一個答案。上面沒有用於ExSlideMenuController的代碼。這是你寫的東西,還是開源的東西? – Stephen