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.
Related
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
I'm sure this is something stupid (it nearly always is when I finally decide to post :) but I can't seem to figure it out, so here goes:
I have a project which contains a UITableViewController (among others) which works fine, but I decided I wanted to enable editing on it and that means it needs to be contained within a UINavigationController. So I added one to the project, set it up so the view is loaded from my table view controller nib, and... it comes up empty. Just a white view with the blue nav controller bar up top.
I've verified that the table view is getting loaded - viewDidLoad runs, at least. Clearly something's not hooked up, probably something in IB, but I just can't seem to see it.
Any suggestions?
In your AppDelegate.h class
UINavigationController *navigationController;
In your AppDelegate.m class
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
navigationController = [[UINavigationController alloc]
initWithRootViewController:viewController];
[self.window addSubview:navigationController.view];
}
Try this. It may solve your problem.
Change the class inheritance from UITableViewController to uiviewcontroller. In the xib put the table view and attach it with an iboutlet for uitableview, set the two required protocols for table view and hope that is done if I am not missing anything.
It seems you forget to pass nib name in the interface builder. Try selecting viewControler inside UINavigation Controller in interface builder and set the nib name and class there. If you by-mistake set the nib name and class name on UINavigation controller remove the nib name and class from there.
Its to use the navigation bar rather than using navigation controller since it can fulfill your requirements.
Just place the navigation bar in Xib file & add an action button event over the button.
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.
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.
Here goes stupid question again :(
I am trying to create a sample app that loads UIViewController when the app loads and the view contains a button to load UINavigationViewController.
Now I created a project with "Window-based Application" and added "RootViewController" in the project with .m, .h, and .xib.
Next I added a view and a button in the "RootViewController.xib" file and it runs ok. After that, I added "UIViewController subclass" file naming "NavViewController" with .h, .m and .xib files.
Also I added - (IBAction)buttonPressed:(id)sender function in the "RootViewController" classes to load NavigationViewController.
Here is the code of the "buttonPressed:".
- (IBAction)buttonPressed:(id)sender {
NavViewController *navViewController = [[NavViewController alloc] initWithNibName:#"NavViewController" bundle:nil];
self.navController = navViewController;
[self.view insertSubview:navViewController.view atIndex:0];
[navViewController release];
}
When I "build and go," it runs fine initially until I press the button. When I press button, program terminates it.
What am I doing wrong? Please help...
Thank you.
What are you doing wrong? Designing your app in a non-standard way - you are not supposed to be able to do this - the NavigationController is in charge!
Why would you have a button that then adds a navigation controller? - it goes against the user interface guidelines. I found it hard to get to grips with the interface guidelines to begin with but you really must because it will make your app so much more usable.
If you need a navigation controller then add it to the view to begin with - or create a new view with the navigation controller. Honestly try it out and you will feel the user interface feels much better.
If you really want a button that adds a navigation controller to the window then do the following:
Keep a reference to the AppDelegate in your code
Use this reference and pass in your current view controller to a method called reloadMainViewWithNavBar:(UNViewController*) viewController
This new method should remove the old mainViewController and create a NavigationController
using your viewController as the root view conroller
add the navigation controller view to window view
The navController has no view set in the nib. A UINavigationcontroller needs a root view. In the nib, connect the navigation controller to a another view controller.
In addition to the fix mentioned above, what you really want to do is create the first view controller contained in the navigation controller - but hide the navigation bar until the button press causes it to unhide. You cannot easily add a navigation controller to a view you are in.