Reputation: 3725
I have a found many tutorials on how to configure SWRevealViewController via storyboards, but I am looking to move away from storyboards and xibs altogether.
So I was wondering, is there a way to configure the library programmatically?
Upvotes: 4
Views: 4432
Reputation: 1
Update for Swift 5.x (Programmatically)
From AppDelegate, in didFinishLaunchingWithOptions:
let revealController = SWRevealViewController()
var mainRevealController = SWRevealViewController()
let sidebar = SideBarViewController()
let homepage = ViewController()
let frontNavigationController = UINavigationController(rootViewController: homepage)
let rearNavigationController = UINavigationController(rootViewController: sidebar)
revealController.frontViewController = frontNavigationController
revealController.rearViewController = rearNavigationController
revealController.delegate = self
mainRevealController = revealController
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = mainRevealController
return true
Upvotes: 0
Reputation: 2207
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
Upvotes: 2
Reputation: 2842
There are sample projects in the SWReveal package that you downloaded. They are all implemented programmatically if I remember correctly.
From the AppDelegate.m of 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;
}
Upvotes: 3