Configure SWRevealViewController programmatically?

I have many tutorials on how to configure SWRevealViewController through storyboards, but I try to completely abandon storyboards and xibs,

So I was wondering if there is a way to programmatically set up the library?

+4
source share
2 answers

The SWReveal package you downloaded contains sample projects. All of them are implemented programmatically, if I remember correctly.

From AppDelegate.m sample project # 2:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window = window;

    FrontViewController *frontViewController = [[FrontViewController alloc] init];
    RearViewController *rearViewController = [[RearViewController alloc] init];

    UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
    UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];

    SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
        initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];

    mainRevealController.delegate = self;

    self.viewController = mainRevealController;

    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}
+3
source

Swift 3

    let frontNavigationController:UINavigationController
    let rearNavigationController:UINavigationController
    let revealController = SWRevealViewController()
    var mainRevealController = SWRevealViewController()

    let sidebar = self.storyboard?.instantiateViewController(withIdentifier:  "sidebarMenuVCID")as! sidebarMenu

    let homepage = self.storyboard?.instantiateViewController(withIdentifier: "HomePageVCID") as! HomePage

    frontNavigationController =  UINavigationController(rootViewController: homepage)
    rearNavigationController = UINavigationController(rootViewController: sidebar)

    revealController.frontViewController = frontNavigationController
    revealController.rearViewController = rearNavigationController
    revealController.delegate = self
    mainRevealController  = revealController

    self.window?.rootViewController = mainRevealController
+2
source

All Articles