Loginviewcontroller before SWRevealviewcontroller with Storyboard objective C - objective-c

I am using SWRevealViewcontroller by using this sample:
I want to add loginviewcontroller before SWRevealViewcontroller.
What I've tried:
Added loginviewcontroller in Storyboard. Set it as InitialViewcontroller.
Inside button action.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
MapViewController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:#"MapViewController"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[navController setViewControllers: #[rootViewController] animated: YES];
[self.revealViewController setFrontViewController:navController];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
But it is not working. Please help

viewController1
viewController2 *viewController2=[self.storyboard instantiateViewControllerWithIdentifier:#"viewController2Id"];
[self.navigationController pushViewController: viewController2 animated:YES];
viewController2
-(void)pushAfterLoginScreen
{
SidebarViewController *sidebarmemu =(SidebarViewController*) [self.storyboard instantiateViewControllerWithIdentifier:#"SidebarController"];
viewController3* viewController3 = (viewController2*)[self.storyboard instantiateViewControllerWithIdentifier:#"viewController2Id"];
SWRevealViewController *revealController;
UINavigationController *frontNavigationController;
UINavigationController *rearNavigationController;
frontNavigationController =[[UINavigationController alloc]initWithRootViewController: viewController2];
rearNavigationController =[[UINavigationController alloc]initWithRootViewController:sidebarmemu];
revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
revealController.delegate = self;
self.swcontroller =revealController;
AppDelegate *app =(AppDelegate *)[[UIApplication sharedApplication]delegate];
app.window.rootViewController =self.swcontroller;
}

SWRevealViewcontroller which is already embed with the navigationController you need to pass control to SWRevealViewcontroller after successful login using presentViewController method by setting up the storyboard id to navigationController of SWRevealViewcontroller and navigate your app using below code:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:#"navContStoryboardID"];
[vc setModalPresentationStyle:UIModalPresentationCustom]; // optional
[vc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; // optional
[self presentViewController:vc animated:YES completion:nil];
Hope this helps you.

Related

Present modal UIViewController over UISplitViewController from AppDelegate

I've written the code below to present a modal UIViewController on top of a UISplitViewController from AppDelegate. However, it keeps throwing Application tried to present modally an active controller <UISplitViewController: 0x138023800>..
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
NSLog(#"%#", shortcutItem.type);
if([shortcutItem.type isEqualToString:#"com.myapp.show-me"]){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UISplitViewController *tc = [storyboard instantiateViewControllerWithIdentifier:#"SplitViewController"];
self.window.rootViewController = tc;
UINavigationController *ivc = [storyboard instantiateViewControllerWithIdentifier:#"Navigation"];
UIViewController *detailViewController = [ivc.viewControllers objectAtIndex:0];
detailViewController.restaurant = #"1";
[tc presentViewController:detailViewController animated:YES completion:nil];
} else if([shortcutItem.type isEqualToString:#"com.myapp.see-all"]){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UISplitViewController *tc = [storyboard instantiateViewControllerWithIdentifier:#"SplitViewController"];
self.window.rootViewController = tc;
}
}
What am I doing wrong with com.myapp.show-me?
As it turns out, I only needed to present the UINavigationController instead of the UIViewController.
[tc presentViewController:ivc animated:YES completion:nil];

Set Root View In App delegate with View Hierachy

I want to be able to manually set the root view controller in app delegate intact with it's view hierarchy
My View Controller Hierarchy is
TabBarController
UINavigationController
FirstViewController
DetailedViewController (I want to show this view)
Currently what I do is
DetailedViewController *vc = (DetailedViewController *)[mainStoryBoard instantiateViewControllerWithIdentifier:#"DetailedViewController"];
[self.window setRootViewController:vc];
[vc performSelector:#selector(setup:) withObject:section];
which obviously ignores the hierarchy and therefore when the app loads, I dont have the nav bar nor the tab bar.
So I tried this
UITabBarController *tabBarController = [mainStoryBoard instantiateViewControllerWithIdentifier:#"tabController"];
tabBarController.selectedIndex = 0;
DetailedViewController *vc = (DetailedViewController *)[mainStoryBoard instantiateViewControllerWithIdentifier:#"DetailedViewController"];
UINavigationController *navController = [mainStoryBoard instantiateViewControllerWithIdentifier:#"NavController"];
[navController pushViewController:vc animated:YES];
[self.window setRootViewController:tabBarController];
But using this code I can view FirstViewController and not the DetailedViewController
Your view hirarchy is such that
You have tabbar that has navcontroller with a rootview of firstviewcontroller so this code add firstview as rootView
UITabBarController *tabBarController = [mainStoryBoard instantiateViewControllerWithIdentifier:#"tabController"];
tabBarController.selectedIndex = 0;
FrstViewController *firstView = (FirstViewController*)[mainStoryboard instantiateViewControllerWithIdentifier:#"FirstViewController"];
UINavigationController *navController = [UINavigationViewController alloc] initWithRootViewController:firstview]
self.tabbarController.viewControllers = [NSArray arrayWithObjects:navController,nil]
[self.window setRootViewController:tabBarController];
When the first we loads in viewDidload of it push detailviewcontroller
-(void) viewDidLoad
{
DetailedViewController *vc = (DetailedViewController *)[mainStoryBoard instantiateViewControllerWithIdentifier:#"DetailedViewController"];
[self.navigationController pushViewController vc];
}

How can i go to storyboard from xib

i am using both storyboard and xib in my project and i want to go xib files from storyboard but can't reverse it. so how i go to storyboard from xib files. thnx in advance.
storyboard to xib:
Dashboard1ViewController *tempView = [[Dashboard1ViewController alloc] initWithNibName:#"Dashboard1ViewController" bundle:nil];
tempView.passemail = [matches valueForKey:#"email"];
[self.view addSubview:tempView.view];
it works fine but xib to storyboard i have used this code
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"loginUI" bundle:nil];
login2ViewController *vc = [sb instantiateViewControllerWithIdentifier:#"login2"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
but it is not working.
Change nil to [NSBundle mainBundle]
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"loginUI"
bundle:[NSBundle mainBundle]];
the following method is working for me. make sure that your identifier is correct
YourViewController *urViewController = (YourViewController *)[[UIStoryboard storyboardWithName:storyboardName bundle:nil] instantiateViewControllerWithIdentifier:#"storyboardID"];
[self presentViewController:urViewController animated:YES completion:nil];

How to push Storyboard from loginviewcontroller which is an xib

I am having Loginview controller,I have created it with Xib and i want to push mainstoryboard on clicking loginbutton.
LoginViewController *lObjloginview = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
UINavigationController *lObjtempview = [[UINavigationController alloc] initWithRootViewController:lObjloginview];
self.window.rootViewController = lObjtempview;
[self.window makeKeyAndVisible];
This will add loginview from xib.but after pressing loginbutton I want to load storyboard.Can anyone help me in pushing mainstoryboard which has tabbar controller inside mainstoryboard to link xib.
Load the initial view controller from the storyboard and present it
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController * initialVC = [storyboard instantiateInitialViewController];
self.window.rootViewController = initialVC;
If you know a priori the class you're instantiating
UITabBarController * initialVC = (UITabBarController *)[storyboard instantiateInitialViewController];

Could not load NIB in bundle with name 'SecondViewController'

I'm trying to push the Navigator Controller to a different view controller but I keep getting the error saying the nib bundle name can't be loaded. Here's the code I'm using:
SecondViewController *vc1 = [[SecondViewController alloc]
initWithNibName:NSStringFromClass([SecondViewController class]) bundle:Nil];
[self.navigationController pushViewController:vc1 animated:YES];
You have to pass the name of the nib file, not the class name:
// Assuming there is a properly set up SecondViewController.xib in your project.
SecondViewController *vc1 = [[SecondViewController alloc]
initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:vc1 animated:YES];
EDIT:
If you're using Storyboards, you have to load your GUI a bit differently:
UIStoryboard *sboard = [UIStoryboard storyboardWithName:#"StoryboardFileName"
bundle:nil];
SecondViewController *vc1 = [sboard instantiateInitialViewController];