How to navigate to different view controllers based on slide out menu

£可爱£侵袭症+ 提交于 2020-01-04 06:01:14

问题


I'm new to Swift and have been trying various thing for many hours now.

Here's how my app looks like:

Ideally I want them to click an option from this pop out menu that will take them to another view. Right now, I'm on the QuotesTimelineViewController but say I want to click on the bookmark button then I'd want to go to the SavedQuotesViewController.

Here is how my storyboard looks like:

The QuotesViewController has a NavigationController embedded in it. When you click the menu button it goes to the NavigationSideController which is presented modally. Now I don't know how to make the segues for what I want to accomplish next.

Here is my code for the NavigationSideController so right now what happens when you click on an icon in the navigationsidebar it dismisses that animation and the navigationsidebar goes away. Maybe you can see all the commented out code.

And here's some relevant code (I think) from QuotesTimelineViewController:

But there could be something I'm missing so if you want to look at my whole repo it's here: https://github.com/mayaah/ios-decal-proj4

Any guidance would be so helpful! Eventually I'd like that whenever I click on an icon in the navigationsidebar the view controller corresponding to that icon opens up. The most progress i've made so far was getting a window hierarchy error! I guess because when I click on an icon, QuotesTimelineViewController isn't the at the top of the stack or something I don't know.


回答1:


I can propose two solutions here

  1. Use a side menu third party library.

There are lot of things to take care of while creating a app side menu including nested heirarchy/rotations, shadows etc. The third party libraries will take care of them easily and are well tested code. You can choose the one you like from cocoacontrols

  1. Use a Navigation Controller and change Active VC on table selection

    The basic idea is to make a new navigationController in your app delegate and make all different type of entry points. so in your app delegate, declare a new UINavigationController variable.

You wont be using the storyboard initialVC in this approach. in didFinishLaunching Method of app delegate

var navController:UINavigationController!

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    // make sure to set storyboard id in storyboard for these VC
    let startingVC =  storyboard.instantiateViewControllerWithIdentifier("QuotesTimeLine");
    navController = UINavigationController(rootViewController: startingVC)
    self.window!.rootViewController = navController
    return true
}

and then in your side menu, you update the navController's viewControllers with new VC

 func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        // make sure to set storyboard id in storyboard for these VC
        let startingVC =  storyboard.instantiateViewControllerWithIdentifier("NewVC");
        let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
        appDelegate.navController.viewControllers = [startingVC]
        dismissViewControllerAnimated(true, completion: nil)
    }

This is still rough but gives the idea of what you need to manage the heirarchy. Let me know if any clarification is needed.



来源:https://stackoverflow.com/questions/36950237/how-to-navigate-to-different-view-controllers-based-on-slide-out-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!