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
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];
SecondViewController *testAppViewController2Obj =[[SecondViewController alloc]initWithNibName:#"TestAppViewController2" bundle:nil];
[self.navigationController pushViewController:testAppViewController2Obj animated:YES];
ContainerViewController *container = [[ContainerViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:container];
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 65)];
container.navigationItem.title = #"Frames";
self.window.rootViewController = nav;
i hope it works
In order to push a new view controller you should first create a view controller, VC1, link it with a navigation controller and then link the navigation controller to the rootViewController in the AppDelegate
#AppDelegate
FirstViewController *VC1 = [FirstViewController new];
UINavigationController *nVC = [UINavigationController alloc] initWithRootViewController:VC1];
self.window.rootViewController = nVC;
Then when VC1 gets pushed, you can create another view controller and push it like this:
#Now in VC1
SecondViewController *VC2 = [SecondViewController new];
[self.navigationController pushViewController:VC2 animated:YES];
Currently I develop with a StoryBoard for the iPad. Additionally I add a ViewController.xib file with a view. Now I want to back button from xib to storyboard. My code is below but this is not working.
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.navigationController pushViewController:initViewController animated:YES];
You can present the View Controller from a storyboard scene, using
- presentViewController:animated:completion: (e.g. for a modally scenario)
ViewController *vc= [[ViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:navController animated:YES completion:NULL];
then, you can add a custom back button
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"Back", #"Back from ViewController.XIB") style:UIBarButtonItemStylePlain target:self action:#selector(backAction:)];
self.navigationItem.leftBarButtonItem = backButton;
and dismiss it:
- (void)backAction:(id)sender{
[self.presentingViewController dismissViewControllerAnimated:YES completion:NULL];
}
Forget about the navigationController.
In your active view controller init the new view controller like this.
UIViewController *initViewController = [[UIViewController alloc]
initWithNibName:#"YourNibFile" bundle:[NSBundle mainBundle]];
[self presentViewController:initViewController animated:YES completion:nil];
And to dismiss.
[self dismissViewControllerAnimated:self completion:nil];
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:)