I've StoryBoard and xib in my project.
I know how to go to xib from storyboard, this is the code:
ChosenPlacesViewController *cpvc = [[ChosenPlacesViewController alloc]initWithNibName:#"ChosenPlacesViewController" bundle:nil];
[cpvc setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:cpvc animated:NO];
But how do I go from the xib to different ViewController in my StoryBoard?
I know I can use:
[self dismissViewControllerAnimated:NO completion:NO];
But I want to go to different ViewController(TabBar StoryBoard), not the last one.
you should find out more about navigation view controller. It depends what is your hierarchy of view controllers. There is a viewControllers property. You can set new order of controllers, last one will be visible.
More info: http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
Related
I have one UIView that I want to use in every of my UIViewControllers. The main UI is designed with Storyboard. The extra UIView has its own XIB.
So I don't want to put the UI of the extra UIView by hand into every UIViewController, and connect the outlets on every UIViewController. So I thought maybe it is possible to create the UI, and the connections in one XIB and then somehow reuse it. Is this possible? If yes how?
Just add this line to your ViewControllers to have a reference to your custom view:
YourView *yourView = (YourView *)[[NSBundle mainBundle] loadNibNamed:#"YourXIB"
owner:self
options:nil].firstObject;
But since you want this custom view in all of your ViewControllers, I recommend having one UIViewController subclass that contains the line above, then subclass that UIViewController for each additional one in your project. That way you'll have a reference to your custom view in each ViewController, but only have to write this line once.
I think it is possible by keeping the same name in the function initWithNibName:, so you can do this in one of your controller:
UIViewController *oneViewController = [[FirstViewControllerClass alloc] initWithNibName:#"MyXIBThatWillStayTheSame" bundle:nil];
[self presentModalViewController:oneViewController animated:YES];
and do this in another one:
UIViewController *anotherViewController = [[AnotherViewControllerClass alloc] initWithNibName:#"MyXIBThatWillStayTheSame" bundle:nil];
[self presentModalViewController:anotherViewController animated:YES];
I'm having problem with accessing my tabbarcontroller in the storyboard when its not the initial view. So basically there is an initial view in the storyboard which leads to the tabbarcontroller. I want to change the color of the tab but i dont have access to it! I know that it can be added to the delegate if its the initial view but in this case its not the initial view in the storyboard! I read somewhere that I have to override a method in the first view but there was no detail about it!
If you are in a viewcontroller in the storyboard then this code:
UIStoryboard *storyboard = self.storyboard;
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"OtherViewController"];
Will get the other viewcontroller youw want and you could do things such as:
set yourself as delegate for it:
[(OtherViewController *)vc setDelegate:self];
display it:
[self presentViewController:vc animated:YES completion:nil];
I think you could use this to get the other viewcontroller and then access the tabbar from it.
Sorry if I misunderstood what you are trying to do.
I have made a very simple Navigation based app (UIViewController). The view has a single button on the Main RootViewController.
Next, I made 2 classes: TabOneViewController, TabTwoViewController. All good. I then created a new Class TabBarViewController. I opened up the NIB file and dropped on a ``UITabBarController onto it. The two tabs it creates in it by default were assigned (respectively) to my TabOne and TabTwo view controllers.
strong text
Then in my TabBarViewController, I made an IBOutlet for a UITabBarController, synthesized it etc etc. I linked it up in Interface builder via the "files owner".
In the RootViewController, I linked the button to my "pushView" method, and in this pushView method, I have the following code:
- (IBAction) pushView {
TabBarViewController *controller = [[TabBarViewController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
The end result is it DOES push a view, but I cannot see the tab bar at the bottom, let alone any of the pages I've added to the controller.
What am I doing wrong? Why can't I link it in IB?
I am not 100% sure if that's allowed.. because you already have one tabBarController as rootViewController, and you dropped one more tabBarController as first tab controller, tabs ll overlap, considering amount of real estate you have on your iPhone, it make sense to not allow a tabViewController inside another
First, you need to allocate your view controller with your nib:
TabBarViewController *controller = [[TabBarViewController alloc] initWithNibName:#"YourNibName" bundle:nil];
Secondly, in IB, click the UITabBarController and go to the identity inspector and make sure you select your custom class. That said, unless you are overriding or adding some functionality you probably don't need the custom class at all, simply use a UITabBarController directly:
UITabBarController *controller = [[UITabBarController alloc] initWithNibName:#"YourNibName" bundle:nil];
The start of the structure is as follows...
UITabBarController -> UINavigationController(s)
From each of the UINavigationControllers, I have a UIBarButtonItem that modally presents a UIViewController.
This UIViewController has a MKMapView with pins at multiple locations. When clicked, they display an annotation with a disclosure button.
Within this UIViewController, it is my intention to push a detail page (UITableViewController) when pressing the disclosure button of the annotation. The method calloutAccessoryControlTapped: receives the appropriate pin, but the transition to the next controller fails.
I have tried every combination of the following methods...
[self.navigationController ...]
[self.parentViewController ...]
[self.parentViewController.navigationController ...]
with the method being either...
presentModalViewController:
pushViewController:
I have done all of these with the UIViewController being on its own, and also with it embedded inside of a UINavigationController.
All of these properties return null...
self.navigationController
self.parentViewController
self.parentViewController.navigationController
This is the first time I've used storyboard for an Xcode project. Am I missing a step?
Try getting rid of the code and implementing the transitions in storyboard by control dragging from the button to the view controller you wish to load modally. When the "Storyboard Segue" menu pops up select "modal". In the modal view controller, I like to use code to return from the modal by calling:
[self dismissModalViewControllerAnimated:YES];
To Presenting Storyboard View Controllers Programmatically scroll to that section in gravityjack on the link provided.
For example, I have a view controller that I created in storyboard which I can call programmatically with the following two statements:
SettingsViewController *settingsVC = [self.storyboard instantiateViewControllerWithIdentifier:#"settingsVC"];
[self.navigationController pushViewController:settingsVC animated:YES];
I am trying to create a reusable "picker". It is basically like a keypad of a phone. Since I will be using this a lot in my iPhone app, I have been frustrated with trying to make it appear.
It is in its own XIB file and has its own UIViewController subclass as the FileOwner.
However, when I instantiate this with:
MonthPickerViewController *mpvc
= [[MonthPickerViewController alloc] initWithNibName:#"MonthPicker"
bundle:nil];
Nothing happens on the screen. Yet is does fire the -viewWillAppear methods, etc.
So, what am I doing wrong either in code or in InterfaceBuilder that is preventing my view to appear?
Are you pushing the view controller?
[[self navigationController] pushViewController:mpvc animated:YES];
Or are you adding the view controller's view as a subView of your current view?
First, make sure you've hooked everything up right inside Interface Builder. An easy gotcha is to forget to connect the View object up to the view outlet of your UIViewController subclass.
Then, as Adam says, you need to actually display the view. Assuming you're doing this inside the code of another view controller, you'd need something like the following if you just wanted the new view to appear ontop of your current view:
[self.view addSubview:mpvc.view];
Of if you are using a navigation controller to stack views:-
[[self navigationController] pushViewController:mpvc animated:YES];