How can I extend UIViewController which is created by XIB? - iphone

I have a general view controller (created by XIB) with some common controls. I want to create child view controller which inherits that general view controller. I want use XIB at both parent view and child views. How can I do that?

Answer of your question, although it seems quite vague question -
I want to create child view controller which inherits that general view controller.
you can simply use like - ChildViewController : ParentViewController
I want use XIB at both parent view and child views.
While loading these view controller you can use initWithNibName: bundle: and pass xib here.

See this tutorial that may help you
I think, this is same as you said you want to use same xib for both view controllers. You need to do some work around but don't work this tutorial will show you how do it.

Related

positioning UIViewController containment children

I was reading the documentation:
You need to decide how many children can be displayed by your view
controller at once, when those children are displayed, and where
they appear in your view controller’s view hierarchy.
But in which method should I position the view controller children's view? Say I have two UIViewController in the container and I want one next to the other.. how do I do this?
In one of my articles I demonstrated how to create a simple dashboard app using UIViewController Containment.
http://www.highoncoding.com/Articles/848_Creating_iPad_Dashboard_Using_UIViewController_Containment.aspx
Each of the child view controllers has a view property. You can set the frame of those views when you add them to your own view.
It depends on the context of the situation that you may have. If you need to display all of the children when displaying the view for the first time, then add the view controllers and views in viewDidLoad ( if using a xib or nib) or in loadView ( if done programatically). If you need to show the child view controllers on demand, like after the touch of button, then you can add the child view controller and associated view in a separate method.
You will need to layout the views of the child view controllers as you would layout any other subviews. Remember view controller containment is just another ways of allowing you to modularize your code.
Check out this link which helps explain how to add the child view controllers: Animate change of view controllers without using navigation controller stack, subviews or modal controllers?
Here is a simple sample project that shows how to add child view controllers:https://github.com/toolmanGitHub/stackedViewControllers
Good Luck!

Calling pushViewController from child controller function

I have a root view controller that subclasses UINavigationController. It loads in a child view with a UIButton. When that button is pressed I want to make a call from the child view's corresponding view controller (lets say ChildViewController) to the UINavigationController's pushViewController: method in the parent controller.
How is this possible without directly referencing the parent view controller? Is it achievable using a standard protocol method or do I have to create my own?
Every UIViewController has a property called navigationController. If a UIViewController is a part of a UINavigationController's stack, you can use the navigationController property in the following manner:
[self.navigationController pushViewController:yourNextViewController animated:YES];
There's no need to access the rootViewController only for pushing a new ViewController on the stack. This could get really awful if you had big navigation stacks.
By the way - Apple states that UINavigationController is not intended for subclassing. Usually, it is a good idea to listen to their warnings and directions, so you may want to revisit the subclassing approach again.
using a subclassed UIViewController which is loaded to the UINavigationController's stack may prove a better approach.
Hope this helps.
The child UIViewController that contains your child UIView and UIButton should have the parentViewController property. You can use that to get a weak reference to your UINavigationController where you can message pushViewController:animated:

How to subclass UIViewController with multiple nibs / xibs?

I would like to subclass UIViewController with multiple nibs.
For example:
BaseViewController has a nib with a label, and is subclassed from UIViewController
SecondViewController has a nib with a button, and is subclassed from BaseViewController.
SecondViewController should also have the label from the BaseViewController.
I have searched an not found any tutorials on this, only tutorials with ways to add UIView's to UIViewControllers, so I'm not sure this is even possible.
Can anyone explain how to do this, or point me in the direction to the resources that show how to do this (or if it's even possible at all)?
I am using a hierarchy of controllers and it works just fine. As long as your correct match nibs to properties at each level, there is no reason you cannot define parent controllers in a hierarchy.
I don't think that what you are asking can be done. A view can be loaded from only one nib. You could have the base view controller set up with a nib, and descendant view controllers do additional setup in viewDidLoad.

Creating an overlay view ontop of EAGLView

I am creating a game using OpenGLES.
Game consists of a view controller and the EAGLView.
I have created another view controller that I want to handle the extra view that go ontop of the EAGLView so things like menu and options.
I have a call from the EAGLView view controller to the extra view controller that adds an IBOUTLET UIView to the appdelegates window however its not appearing. The methods being called but no view is being added.
Probably a really easy and stupid question but I cant work it out.
Thanks for any help in advance
Ok I have done it a different way.
I use a view Controller called GameViewController to load up and i add its subview to the window in the appDelegates applicationDidFinishLaunching method
Then i call a method to add another view controllers view (my open gl view) to the subview. This means I can then put other views over the top.
I don't know why i didn't do this before to be honest
Thanks for your help
Can you be more specific with this sentence:
I have a call from the EAGLView view controller to the extra view controller that adds an IBOUTLET UIView to the appdelegates window however its not appearing.
One approach is to use navigation controller that could be initalized with EAGLView controller as root. So, you can push and pop in navigation controller another view controller that handles the game menus.
Another approach is to present menu as modal view controller. This can be invoked with presentModalViewController: in current EAGLView controller.

Design view in Interface Builder to load lazily in UIViewController

I've managed to get my myself confused... I've got a fairly complex View Controller much of which is developed programatically. I'd like to pop up a "dialog" on top of the view controller at some point and I'd like to "design" that view in Interface Builder because it's fairly straightforward (background UIImageView, some UILabels and a UIButton).
I've created the .xib and am now subclassing UIView with the IBOutlets,etc. I'm now trying to wire it up and realizing I probably need to add an initWithNibName: method so this will instantiate correctly...then I realize that I'm really just making another UIViewController and I don't think we're supposed to have UIViewController views w/in other UIViewController views?!?
So now I'm re-thinking how to go about this "correctly." How best to use IB to design a simple 1/4 screen view that will pop up over a main view?
Call +[NSBundle loadNibNamed:owner:] to load the NIB file that contains your view. If you specify your view controller (i.e., self) as the owner, any connections you make to File's Owner in the NIB file will then be made to the view controller. So you could declare an outlet to your custom view in the view controller and after the call
[NSBundle loadNibNamed:#"MyView" owner:self];
the outlet variable will point to the view object. Alternatively, you can use -[NSBundle loadNibNamed:owner:options:], which returns an array of the top-level objects in the NIB.