In iOS,Navigation show Navigation - ios

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];

Related

Navigation bar not appearing when pushing a controller from a presented ViewController

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.

How to pass property to root view controller while presenting UINavigationController?

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];

How to navigate the navigationcontroller rootviewcontrollr subview controller

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;

How to add navigation controller programmatically?

I use code below, but it is not loaded:
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
self.mapViewController = [storyboard instantiateViewControllerWithIdentifier:#"MapViewController"];
self.navigationController = [[UINavigationController alloc]initWithRootViewController:self];
self.navigationBar = [[UINavigationBar alloc]init];
[self.view addSubview:self.navigationBar];
[self.navigationController.navigationController pushViewController:self.mapViewController animated:YES];
try as below
UIViewController *bbp=[[UIViewController alloc]initWithNibName:#"UIViewController" bundle:nil];
UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:bbp];
// [self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
[self.navigationController pushViewController:passcodeNavigationController animated:YES];
[passcodeNavigationController release];
Add this code to your AppDelegate.m in the didFinishLaunchingWithOptions function:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"YOUR_STORYBOARD_NAME" bundle:nil];
yourViewControllerClassName *vc = [sb instantiateViewControllerWithIdentifier:#"YOUR_VIEWCONTROLLER_ID"];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
yourViewControllerClassName is the .h and .m file name that is linked to your viewController.
YOUR_STORYBOARD_NAME is the name of your .storyboard file. For example, fill in Main if your .storyboard file is called Main.storyboard.
YOUR_VIEWCONTROLLER_ID is the ID for your veiwController. You can edit it in the Identity inspector.(See photo)
Hope this helps:)

Push action for UIPopOverController

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

Resources