iPhone Tab Bar Controller and Navigation Controller in outside file - iphone

I have an app which contains
exampleTabAppDelegate (.h and .m files)
MainWindow.xib
In MainWindow.xib, I have the following structure of my objects
Tab Bar Controller - has outlet and is set as rootViewController
Tab Bar
First View Controller - type UIViewController
Navigation Controller - type UINavigationController
View Controller
Also I have a NavigationController class which extends class UINavigationController (.h and .m files named NavigationController)
And for this class I have NIB file named NavigationController.xib.
So next, if I set property Class of Navigation Controller to NavigationController it's works and I get Log message which nested in NavigationController.m method viewDidLoad
But I also have NIB file for my NavigationController and it has its own NavBar but I don't see it.
When I try to set property NIB Name of Navigation Controller to NavigationController, I think it should load my NIB file, but I get an exception and nothing is written to the log/console.
What do i need to do?
I want to have MainWindow.xib file with structure but design of navigation controller view set one another file.
Help. How can i do it?

Related

iPhone: how to create two controller in one NIB file?

I'm a little bit lost. I have created a small app that is starting with a tab bar and in one of its view there's a button that should open a Navigation view that contains a table view.
In my NIB file I have put a Navigation Controller that contains a TableView Controller. I have created a sub-class called MyTableViewController which inherits from the UITableViewController. In the NIB I have configured the Custom Class of the TableViewController with my subclass MyTableViewController.
When the button of my App is tapped, I'm loading the NIB file with the initWithNibName but it returns me a UINavigationController.
How does it work to request the creation of MyTableViewController and get a pointer on it when I'm loading my NIB?
Thanks,
Sébastien.
This one has caught me out a few times.
When you do initWithNibName it will take the class from the custom class of the File's Owner, not the custom view of any objects .
I dont actually bother subclassing from UITableviewController any more. Just create a view controller and drag in a table view as a subview. Just make sure you hook up the data source and the delegate.
Link your TableViewController to an IBOutlet so you don't have to mess with initWithNibName.

Changing the ViewController in NIB

I created a VIEW based application named ktemp1. and It generated .., ktempView1Controller.h and ktempView1Controller.m..,
Later I created one more view.., say "ktemp2ViewController.h" and "ktemp2ViewController.m".
I have a navigationController defined in AppDeligate with rootViewController set as ktempView1ViewController., Having done this All Works fine..
BUT, What I want is to set ktemp2ViewController as the rootViewController.
To do this, I am changing the ViewController class in MainWindow.Xib to ktemp2ViewController and changing the rootViewController to ktemp2ViewController.., But whenever I run the application, I am getting ktempView1 as the rootView and even when I click on the ktemp2ViewController in MainWindow.Xib , the view in IB is getting loaded from ktemp1ViewController...
Can anyone guide me ?
In the standard apple template, you will find something like this in your AppDelegate didFinishLaunching.
window.rootViewControlller = self.viewController;
There should be only a single rootViewController in your application and you should not attempt to set it frm anywhere else than the AppDelegate.
So what is relevant in your case, is the viewController property of the appDelegate. When you look at your MainWindow.xib, you need to make sure it contains a kTempViewController2 and that is wired to your AppDelegate.viewController property (the AppDelegateshould be the MainWindow.xib owner).
I hope you have Navigation controller in your mainWindow.xib.
Explore it and you could see a view controller (root view controller) and other view controller, if any.
Select the root view controller, set its class type and specify its nib name.

UIWebView error on Tab Bar Controller

I really need help on creating a UIWebView on a Tab Bar Controller. But I Bumped into a road block.
Basically I started out with the Tab Bar Application Template, then;
Removed the First and Second Controller XIB files on the resource folder (since it's not really needed
In Interface Builder, I removed default contents in the First and Second View Controller and added a View first, then a Web View after that on both the View Controller
After that, I started coding on both on the First and Second View Controller headers with just this code:
#interface FirstViewController : UIViewController { IBOutlet UIWebView *twitter; }
(also for the Second View Controller's header)
Then I linked the Outlets to the UIWebView and linked both Tab Bar Item to their Class View Controller (First Tab Bar Item linked to the FirstViewController class, then for the second one as well)
Later in both the View Controller's .m files, I added
- (void)awakeFromNib
{
[twitter loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"twitter.com"]]];
}
(and for the other one)
Now when I compiled the application, it gave me:
'First View Controller (First)' has both its 'View' and 'NIB Name' properties set. This configuration is not supported.
I looked through every youtube video about this topic, but none of their comments even mentioned anything about this kind of error, I hope someone can explain how to get through this error, thanks
In Interface Builder you can either define a view in your MainWindow.xib directly inside the TabBarController, or you can tell Interface Builder that those views are loaded from separate XIB files.
It sounds to me like you are defining the views directly inside your main XIB, so in that case you need to select the view controllers that are in the TabBarController, hit Apple-1 to open the attributes pane for the controller, and clear the "NIB name" field which is probably still set to "FirstViewController". Do the same for any other view controllers you have in your TabBarController.

Everything is wrong when I modified standard UITabBar application

I created "New Project" -> Tab Bar Application.
Then i changed from #interface FirstViewController : UIViewController to #interface FirstViewController : UINavigationController.
Then i changed file's owner from UIViewController to UINavigationController in xib file.
Then i updated view. But i don't see any label on the screen. Why? (i have some labels on xib)
Why are you subclassing UINavigationController and what are you trying to accomplish? UINavigationController does not display a view of it's own, just the navigation bar over some other view controller's view. In addition UINavigationController was not designed to be subclasses, hence the "This class is not intended for subclassing." warning in its class reference.
If you want to display your view controller as part of a navigation stack you should create an instance of UINavigationController, set that navigation controller as the view controller for one of your tabs, and then push an instance of your FirstViewController onto the UINavigationController.

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.