Eddwin Paz
Eddwin Paz

Reputation: 2878

Connect SWRevealViewController with rear and 2 viewcontrollers using Swift With no storyboard

Currently I'm moving all my storyboard Viewcontrollers to be made all by code, By that I mean I'm manually creating every object and positioning it using auto-layout manually, the issue that I came up is that I need to be able to still use de sidebar using the library SWRevealViewController.

I want to setup on my AppDelegate.swift the connection between the rear, the sidebar menu tableview and my main viewcontroller. any Idea how to do this by code? I did it well using Storyboard following a tutorial www.appcoda.com/sidebar-menu-swift/ but by code does not seem to me quite clear.

Upvotes: 0

Views: 109

Answers (1)

Eddwin Paz
Eddwin Paz

Reputation: 2878

The solution I've found is the following.

    // Start  Side Bar

    window = UIWindow()

    // ViewControllers 

    let frontViewController = content_feed() // Visible by default
    let rearViewController = sidebar_menu() // Sidebar when user slides left

    let frontNavigationController = UINavigationController.init(rootViewController: frontViewController)
    let rearNavigationController = UINavigationController.init(rootViewController: rearViewController)        
    let revealController = SWRevealViewController.init(rearViewController: rearNavigationController, frontViewController: frontNavigationController)
    revealController.delegate = self


    // SWRevealViewController Settings

    revealController.rightViewRevealOverdraw = 0.0
    revealController.bounceBackOnOverdraw = false
    revealController.stableDragOnOverdraw = true

    // Tell Window to set revealController as our main VC 

    window?.rootViewController = revealController
    window!.frame = UIScreen.mainScreen().bounds
    window?.makeKeyAndVisible()

Upvotes: 1

Related Questions