in my application i mentioned the tab bar controller with 2 tabs tab1 and tab2.And each tab having the navigation view controller with root view controllers.And my scenario is like below
tab1 -> viewcontroller1 (navigationcontroller rootviewcontroller) -> viewcontroller2.
So now i want to move directly from app delegate to view controller2.How is it possible.
I did this one like this in app delegate. But it's moving to viewcontroller1.
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main"
bundle: nil];
self.tabbarController = [mainStoryboard instantiateViewControllerWithIdentifier:#"tabbarcontroller"];
[self.tabbarController setSelectedIndex:1];
viewcontroller2 *view =(viewcontroller2 *) [mainStoryboard instantiateViewControllerWithIdentifier:#"view2"];
[self.tabbarController.navigationController pushViewController:view animated:YES];
self.window.rootViewController=self.tabbarController;
Tab1 -> Viewcontroller1(navigationcontroller rootviewcontroller) -> Viewcontroller2
I have used this approach some times
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main"
bundle: nil];
self.tabbarController = [mainStoryboard instantiateViewControllerWithIdentifier:#"tabbarcontroller"];
[self.tabbarController setSelectedIndex:1];
viewcontroller1 *view1 =(viewcontroller1 *) [mainStoryboard instantiateViewContro1llerWithIdentifier:#"view1"];
viewcontroller2 *view2 =(viewcontroller2 *) [mainStoryboard instantiateViewControllerWithIdentifier:#"view2"];
[self.tabbarController.navigationController pushViewController:view1 animated:NO];
[self.tabbarController.navigationController pushViewController:view2 animated:YES];
self.window.rootViewController=self.tabbarController;
Related
I have following code to present a UIViewController (named A) with UINavigationController.
I have kept navigation bar hidden as I do not want it on A by using following code
[self.navigationController.navigationBar setHidden:YES];
but when I push UIViewController named B I want the navigation bar to be displayed but it's not working even If set
self.navigationController?.setNavigationBarHidden(false, animated: false)
on UIViewController B. Can someone help me in this?
Here is the code to present UIViewController A
AppDelegate* delegate = [AppDelegate applicationDelegate];
UIStoryboard *story = [UIStoryboard storyboardWithName:STORYBOARD_MAIN bundle:nil];
SelectionViewController *tutorial = [story instantiateViewControllerWithIdentifier:#"SelectionViewController"];
tutorial.providesPresentationContextTransitionStyle = YES;
tutorial.definesPresentationContext = YES;
[tutorial setModalPresentationStyle:UIModalPresentationOverCurrentContext];
tutorial.delegate = self;
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:tutorial];
navController.modalPresentationStyle = UIModalPresentationFullScreen;
[navController.navigationBar setHidden:YES];
navController.providesPresentationContextTransitionStyle = YES;
navController.definesPresentationContext = YES;
[navController setModalPresentationStyle:UIModalPresentationOverCurrentContext];
[delegate.tabBarController presentViewController:navController animated:YES completion:NULL];
Here is the code to push UIViewController B
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"AppDetail" bundle:nil];
DetailViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"DetailViewController"];
[self.navigationController pushViewController:vc animated:YES];
[[self navigationController] setNavigationBarHidden:NO];
Additional information
UIViewController A is in different storyboard and B is in different
A's code is written in OBJ-C and B's code is in swift.
I try to Use Navigation show Navigation,but the transitions animation is From down to up.
UIViewController2 * vc2 = [[UIViewController2 alloc] init];
UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:vc2];
[self.navigationController showViewController:nav sender:nil];
Try.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
SecondViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"ViewControllerB"];
[[self navigationController] pushViewController:vc animated:YES];
I'm doing in-app browser to open links w-out using safari from any viewController in app.
This is a code for launching browser with link in AppDelegate.m
-(void)openExternalRef:(NSString *)ref
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
CSDBrowser* browser = [storyboard instantiateViewControllerWithIdentifier:#"CSDBrowser"];
browser.urlString = ref;
browser.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.window makeKeyAndVisible];
UINavigationController* navi = [storyboard instantiateViewControllerWithIdentifier:#"CSDBrowserNavi"];
[self.window.rootViewController presentViewController:navi animated:YES completion:nil];
[self.window.rootViewController.navigationController pushViewController:browser animated:YES];
}
i need to pass a variable "ref" to my viewcontroller, but i need to launch navigation controller first, any ideas?
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
[self.window makeKeyAndVisible];
UINavigationController* navi = [storyboard instantiateViewControllerWithIdentifier:#"CSDBrowserNavi"];
CSDBrowser* browser = [navi viewControllers][0];
browser.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
browser.urlString = ref;
[self.window.rootViewController presentViewController:navi animated:YES completion:nil];
I have used UISplitViewController on Storyboard, i have set UINavigationController both for master and detail viewcontroller. Master ViewController is loaded, but Detail ViewController does not load.
I could not figure out what might be wrong?
Could you please help me?
My code on AppDelegate is as follows;
if([Utils isIpad])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main_iPad" bundle:[NSBundle mainBundle]];
UISplitViewController *splitViewController = [storyboard instantiateViewControllerWithIdentifier:#"splitViewController"];
//UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:#"navigationViewControllerMaster"];
splitViewController.delegate = (id)navigationController.topViewController;
[self.window setRootViewController:navigationController];
}
I created a pop over to view my settings like this,
if ([popoverController isPopoverVisible]) {
[popoverController
dismissPopoverAnimated:YES];
} else {
UIView* popoverView = [[UIView alloc]
initWithFrame:CGRectMake(566, 440, 0, 0)];
popoverView.backgroundColor = [UIColor blackColor];
controller1.contentSizeForViewInPopover = CGSizeMake(300, 115);
popoverController = [[UIPopoverController alloc]
initWithContentViewController:controller1];
[popoverController presentPopoverFromRect:popoverView.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}
my push action code:
UIStoryboard *storyboard = [UIStoryboard
storyboardWithName:#"MainStoryboard"
bundle:nil];
UIViewController *controller = (UIViewController *)[storyboard
instantiateViewControllerWithIdentifier:#"PCBViewController"];
[self.navigationController
pushViewController:controller
animated:YES];
In my settings popover has some buttons. Those button is clicked, view controller open through push action but its not working.
My Question is: How to set push action for popover contents.
Your view is presented from popover thus self.navigationController will be nil.
Try this
UIStoryboard *storyboard = [UIStoryboard
storyboardWithName:#"MainStoryboard"
bundle:nil];
UIViewController *controller = (UIViewController *)[storyboard
instantiateViewControllerWithIdentifier:#"PCBViewController"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
[navigationController
pushViewController:controller
animated:YES];
you need to set up navigation controller for the view controller to allow navigation.
in your .h file
UINavigationController *navevent;
UIViewController *yourViewController
in .m file synthasize it and in view did load
navevent=[[UINavigationController alloc]initWithRootViewController:yourViewController];
yourViewController=[[UIViewController alloc]init];
then create your popover like this
yourViewController.view = yourView;
self.popoverController = [[UIPopoverController alloc]initWithContentViewController:navevent] ;
hope this help