Loading view from another storyboard into view of another storyboard - ios5

I have a requirement like this.
The app is implemented like a slide panel UI which we find in facebook or path app.
I am using JSSlidePanel (https://github.com/gotosleep/JASidePanels) and it requires 3 controllers to be added,
slidePanellcontroller.leftPanel = leftsideViewController;
slidePanellcontroller.centerPanel = centerViewController;
slidePanellcontroller.rightPanel = rightsideViewController;
I created a separate storyboards for slidePanellcontroller and for centerViewController. slidePanellcontroller is loaded from main storyboard, and centerViewController will be loaded from another storyboard called tabbar storyboard. Basically centerViewController is a tab bar controller.
Now I am not sure how to add the centerViewController's view into the slidePanellcontroller view.
Please provide any inputs.
Thanks,

Firsts instantiate the other storyboard:
UIStoryboard otherStoryboard = [UIStoryboard storyboardWithName:#"otherstoryboardfilename" bundle:nil];
Then instantiate the view controller by the identifier you set for it in Interface Builder.
UIViewController *centerViewController =
[otherStoryboard instantiateViewControllerWithIdentifier:#"centerViewControllerIdentifier"]

Related

Using A Button To Change Pages InXCode

I'm making an app in xcode for iphone with multiple pages. How can I change to a different page in the app by clicking a button?
One easy way, as Aaron mentioned, is to embed your view controller inside a Navigation Controller. If you are using storyboard, then select your view controller on the storyboard, and click menu item Editor -> Embed In -> Navigation Controller. And for trying how navigation will work, add a push segue from your login button on the login view controller to another view controller (your new 'page' where you want to navigate to will be another view controller on the storyboard) by Control +
clicking + dragging from the button over to the other view controller.
You can also navigate to another view controller programmatically without the segue. On the method that's called on Login button click, you can call another view controller (new 'page') like this:
// Create a new view controller
UIViewController *myController = [[UIViewController alloc] init];
// If you have the view controller defined in the storyboard, and you have give it a Storyboard Id, let's say "MyViewController", you can get it like this:
// UIViewController *myController = [self.navigationController.storyboard instantiateViewControllerWithIdentifier:#"MyViewController"];
// Push/Navigate to the new view controller
[self.navigationController pushNavigationController:myController animated:YES];
Hope that helps.
You could use this:
UIViewController *viewControllerYouWant = [[UIViewController alloc] init];
[self presentViewController:viewControllerYouWant];
If you touch the login button you go to the other view. And if you are on the other view use the same code just including the viewcontroller you want to go.

How to add ViewController on top of tabBarViewcontroller using storyboard?

In my application i want to add a viewcontroller with nib on top of tabbarviewcontroller using storyboard.
for eg; when the application launch for first time i want to show that view controller for once and after that when ever user start the application it should show the tabbarviewcontroller. and not the viewcontroller.
following is my code
-(void)viewDidAppear:(BOOL)animated
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateInitialViewController];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:vc animated:YES];
}
I'm a little confused with how you described what you want. There are a couple of ways to do what you want and depending on how you want things to flow.
Storyboard
If you stay in the storyboard, you can add a UIViewController - in front of your tabbar (to the left of) controller. Basically, add a UIViewController and move the start arrow to it. then create a segue from it to your tabbar controller. You can bring in the tabbar controller via a push segue or even as a modal segue if you want.
You would have to move your xib file into the storyboard.
It would flow like this: UIViewController -> UITabbarController -> Rest of your app.
In this model, the first view controller would always be available on launch.
Another strategy - trying to keep things simple is to use the first view controller attached to the tabbar. It would align with the left most tab.
That view controller gets instantiated and put on screen by the tabbar controller first under normal conditions. You can add code in that UIViewController in the ViewDidLoad or ViewDidAppear methods to instantiate and put up the modal view using either a storyboard or a nib file.
Finally, the last way I can think of would be to load the nib file from your app delegate then display your tabbar from the storybook as a modal. I think this approach is the least desirable, but doable.
hope that helps. good luck.

Storyboard: inferring navigation bar after changing segues

I am developing a navigation-based app with few views. In the Storyboard, I have a Navigation Controller that points to my main ViewController ("center" view of my app) that points to other views with segues.
At first I wanted this segues to be push but it didn't work properly (the buttons were hardly responding), I've switched to modal (as advised here). Now the segue works fine but whenever I use modal segue, the navigation bar in view it points to disappears (I've tried with other configurations - the navbar is being shown on Storyboard but doesn't work on Simulator).
Where am I making mistake?
With a modal presentation your view controller is no longer part of the UINavigation stack. You can drag in a new UINavigationController, display that as a modal view and have your view controller class the root view controller of the navigation controller.
As suggested by JoePasq, "Have your view controller class the root view controller of the navigation controller". Select your view controller which you want to set as Root screen and goto Editor/EmbedIn option and select navigation controller. You will get a navigation-controller embedded with your root view controller. Instead of setting up segues you can change your screens programmatically in your program. In your method for button click event write a similar code as below;
- (IBAction)okPressed:(id)sender {
UIStoryBoard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle: nil]; //MainStoryboard is the name of your storyboard
SecondViewController *secondView = [storyboard instantiateViewControllerWithIdentifier:#"sView"];
//sView is the identifier name set by the user, (present inside Attribute Inspector - View Controller)
[self.navigationController pushViewController:secondView animated:YES];
Let me know if this works or there is also another way to do it.

Add Custom Made View in Interface Builder to Another View?

I have a custom UIViewController in Interface Builder (in my storyboard) and I want to add this view I assembled into another view programatically. I have made a class for the view controller I made but simply importing and adding that custom class as a subview doesn't appear to work.
Any help much appreciated, as always.
You'll need to load an instance of the view controller from the UIStoryboard object and add it's view as a subview. That code would look something like this:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
MyViewController* myVc = [storyboard instantiateViewControllerWithIdentifier:#"ident"];
[self.view addSubview:myVc.view];
Make sure you set the identifier field for your view controller in IB and pass that to the "instantiateViewControllerWithIdentifier" method.

Loading UINavigationController from another nib automatically by UITabBarController

I think I've found the cause: Document Info window in IB has a warning: "'Selected Navigation Controller (Second)' has nib name property set to 'SecondView.nib', but this view controller is not intended to have its view set in this manner."
Bummer.
I've built nib in Interface Builder that has UITabBarController at top level and switches between UINavigationControllers.
It works fine when everything is in a single nib file, but I'd like to use separate nib files for UINavigationControllers.
Starting with Apple's TabBar template, if I just change class of SecondView to UINavigationController, it all breaks:
and all I get is this:
// imgur has lost the image, sorry //
Is it possible to have separate file for UINavigationController without programmatically setting everything?
I would like TabBarController to handle loading and unloading of nibs.
Simply swap the UINavigationController with the FirstViewController.
So the hierarchy should be like this:
Tab bar controller
-----Tab bar
-----Navigation Controller
----------First View Controller
---------------Navigation Item
----------Tab bar item (First)
-----Navigation Controller
----------Second View Controller
---------------Navigation Item
----------Tab bar item (Second)
You set the nib of First View Controller in the inspector to the nib file containing the actual view objects (Since you are trying to split them into separate files, which is a good thing).
You have one tab, that tab has a navigation controller which loads First View Controller as its root view.
Done.
I haven't tried setting up UINavigationController via IB. I have multiple screens, each is stored in separate xib and there's a corresponding class that extends UIViewController. In applicationDidFinishLaunching I initialize UIViewControllers using xib's but then manually create UINavigationController, add navigation controller's view to window and push first view to navigation controller.
Not sure if that helps.
- (void)applicationDidFinishLaunching:(UIApplication *)application {
navigationController = [[UINavigationController alloc] init];
FirstViewController * viewController = [[FirstViewController alloc]
initWithNibName:#"FirstView"
bundle:nil];
[navigationController pushViewController:viewController animated:NO];
[viewController release];
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
}
Above FirstViewController extends UIViewController, in IB you create your view then set File's owner class to your class (e.g. here FirstViewController) and connect the File's owner view to the UIView's view.
I believe you are looking for something like this. You would replace "whatever" with the name of you second nib file.
newNavController = [[UINavigationController alloc] initWithNibName:#"whatever" bundle:[NSBundle mainBundle]];
First, it looks like you have your UITabBarItems under the navigation controllers instead of directly under the UITabBarController. That may be part of your problem.
Second, when you add a UITabBarController in IB and and click on its icon in your list of top-level objects (your first screenshot), the attributes inspector will allow you to change the type of view controller for each of the tabs. Using this, you can change them all to navigation controllers, if you wish. Also, since you wanted to load custom views and view controllers from other nibs, if you look at the "View Controller" section at the bottom of the attributes inspector, you can select a nib from your project to load the view from. Assuming that nib's "File's Owner" is set to your UINavigationController subclass, it should all work fine.
All of this without a large amount of coding work, either. Let me know if you'd like screenshots for what I'm talking about in case you can't find these panels.
I found the same warning.I have kept all view controller in separate xib files. I got rid off it by removing .nib name and keeping it empty.