UIWebView error on Tab Bar Controller - iphone

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.

Related

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.

Converting an Utility application (2 view controllers) to a Tab bar Application

As the title suggests, I have built an utility based app.
The app consists (at the moment) of 2 view controllers + a model class hierarchy.
The thing is , as I'd like to add some features to the app , I would like to convert it to a TabBar based application.
As a first step , I would like the first view to be the first view of the tab bar , and the flipSideView to be one of the other tab bar items.
Is there any "standard procedure" / "grocery list" for such tasks ?
I'm sure some of you have encountered the same problem , and would love some advice on "slicing up" the app , and "wiring it up" after creating a new nib file for the main window (is that the first step ? )
Thanks in advance.
I would probably start as follows (assuming you are using Interface Builder and using the standard Xcode utility app template):
Edit your MainWindow.xib file and drag a Tab Bar Controller object into the top level of your view hierarchy.
The default tab bar controller in IB includes two view controller items as examples. Click the first one and change its class to be your existing Main View Controller class.
You can also set the icon and tab bar title for the main view controller item by adding the associated Tab Bar Item that IB has already added to the view hierarchy.
Do the same for the second tab bar item setting the class for the FlipsideViewController.
Delete the old version of your Main View Controller from the NIB file and also remove the IBOutlet property from the Application Delegate (you probably also have references to the main view controller in dealloc which should be removed).
In your App Delegate add an IBOutlet property for the Tab Bar Controller as follows (don't forget to synthesise the property):
#property (nonatomic,retain) IBOutlet UITabBarController *tabBarController;
In IB wire up the tabBarController outlet from the App delegate object to the Tab Bar Controller object.
Finally to get the tab bar controller to show up in place of the main view controller change the code in application:didFinishLaunchingWithOptions: to the following:
[self.window addSubview:self.tabBarController.view];
This should get the basic tab bar app up and running and you can add additional view controllers to the tab bar.
Since you no longer want to flip between the MainView and FlipsideView you can remove the references to the FlipsideViewControllerDelegate from the MainViewController along with the info button and its IBAction method showInfo. Likewise in the FlipeSideViewController you should remove the done button from the view and its IBAction method as these no longer make sense when used with the tab bar.
so, step by step :):
1. declare UITabController outlet in your app delegate.
2. in MainWindow.xib: first drag the instance of UITabBarController in document window, then make connection from app delegate to that instance. now you can set MainViewController as UiTabBarController's first tab viewcontroller, then set FlipsideViewController as UiTabBarController's second tab viewcontroller.
3. in app delegate's appDidFinishLaunching replace [self.window addSubview:mainViewController.view]; with [self.window addSubview:theNameOfUITabBarControllerOutlet.view];. that will do the work. sorry, I don't know your background, that's why I'm not very specific about performing a particular action I decribe, so let me know if you find yourself stuck

Could someone post instructions for how to create a modallly presented tab bar controller?

I'm just trying to make the most basic tab bar controller that gets presented modally. I want to use nibs, as opposed to doing it all programatically, but I really don't understand Interface Builder:
Why can't I drag a tab bar controller into my veiw?
Why does IB create another "window" when I drag a TBC to the document window?
Why are there 2 view thingys in the same nib?
Why do I get this message (crash) when I try to present the modal view: "nib but the view outlet was not set" ?
How do you remember which little connections you need to make in IB, other than the obvious ones you reference in the code?
Is there an IB tutorial out there that goes beyond just the most basic pre-made application templates and actually explains what's going on?
Why can't I drag a tab bar controller into my view?
Because only other views can be dragged onto views. A view controller is not a view.
Why does IB create another "window" when I drag a TBC to the document window?
Because every view controller has its own main view. If you double click a view controller in IB, its view opens.
If you really want to create all controllers from a NIB file, do it like this:
Create a fresh empty XIB file called "TabBarController.xib". It contains nothing but the entries for File's Owner and First Responder.
Drag a UITabBarController into this XIB. Ignore the view that gets opened (you can close it).
Configure the tab bar controller according to your needs, especially by dragging as many UIViewController objects (or UIViewController subclasses) onto the tab bar controller as you have tabs. If these child view controllers should be instances of your custom view controller subclasses, make sure to set their classes accordingly in the Inspector.
For each child controller of the tab bar, create another XIB file in Xcode, this time using the View XIB preset. Let's call these "ChildController1.xib", ... Open all of them in IB and set their File's Owner class to the class of the corresponding child controller (i.e., UIViewController or a subclass). Then connect the views in these XIB to the view outlet of File's Owner. Configure these views as you need them (by adding the actual UI elements of the child views and possibly connecting other outlets if necessary).
Close the child XIBs and return to TabBarController.xib. For each child controller, open the Attributes Inspector and set its NIB Name attribute to "ChildController1", "ChildController2", ... Then close the XIB.
In your code:
NSArray *nibFile = [[NSBundle mainBundle] loadNibNamed:#"TabBarController" owner:self options:nil];
UITabBarController *tabBarController = [nibFile objectAtIndex:0];
[self presentModalViewController:tabBarController animated:YES];
I broke down and just configured the TabBarController without using Interface Builder. The more I'm getting into iPhone development, the more I'm realizing that IB is bad, and to not use it except for the rare components with absolute layouts. In this case, all you would gain by using it would be the icons and titles on each tab. IB doesn't really provide any earth-shattering visualization on that.
I really wish nibs rendered down into some readable text format, so you could always drop to the code to understand what was going on, but that's not the case, so I'll gladly add 6 lines of code to make my program not crash

How do I set a view programmatically for my tabBarController?

I have a tabBarController xib. I've set the first item's class to a view controller I made (.h and .m files, no .xib). When I try to push the tabBarController, I get a warning saying the tabBarController "view outlet was not set".
I'm not sure how to set the view outlet, since I am loading from another view. I'm expecting the default grey view with detailed edges will load from my ViewController.h file because I set the class there, but instead I'm crashing with that error.
Suggestions?
Normally, you would add view controllers to the tab bar controller in the xib. They need to have a view linked up, which you can also do in IB.
If you want to do that programmatically, you should, after loading the xib, but before showing the vc, take the elements of
NSArray *vcs = [tbCtrl viewControllers];
walk through them, and set their view property to a view. When pushed, the tab bar controller will know which view to load: namely the view of the first tab. These things are really much easier to handle in IB.

How to load viewController from a nib file

I have a Tab bar bases project (along with navigation control), inside a particular tab there is a tableViewLoaded , when i click on the table rows it shoud open another view , ie it pushes another controller , i have a view controller in the MainWindow.nib for this view also with some items like buttons labels , but whn i click it doesnt show up anythng only a blank page cums up , can any one help me out with this .
You should generally use one view controller-per-nib file; it makes things much easier. A few things to check:
Is your view controller object being created (set a break point in its init, loadView, or viewDidLoad methods)
Is your view being displayed (set a breakpoint in your viewWillAppear: or viewDidAppear: methods)
Is your view properly hooked up (make sure the view outlet in IB is hooked up correctly; this is a common mistake)
If your question is actually how to load a nib file that's paired with a UIViewController subclass, take a look at UIViewController's -initWithNibName:bundle: and -loadView methods.