In my appDelagate I have a UIViewController called "FrontPage" which is basically a log in screen. Once the login has authenticated it removes itself from the superview and creates a tabbarcontroller, navigationcontroller (inside tabbar), and various UIViewControllers in the NC and on their own in the tab bar. I then push my TabBarVC.view to the windows subView.
It works but I was hoping after I set the windows subview to TabBarVC.view I could release the TabBarViewController to dealloc it and the appdelagate would own the TabBarVC, but when I do it's crashing.
As I'm typing this I'm realizing I never pass the actual TabBarVC, just the view but is there a way to do this?
Also if I completely FUBAR'd this up let me know.
You should set the window's rootViewController property to your UITabBarController instance similar to this:
// set the tab bar controller as our root view controller
[self.window setRootViewController:tabBarController];
To clarify, this will add the TabBarController, its view and all of its subviews to the window's view hierarchy for you and I would recommend you use this method for your login view controller as well.
You could make your UITabBarController an IBOutlet to the app delegate (or just keep the code you have that generates it). Make it a retained property of the app delegate, synthesize the property, and either create the UITabBarController in the app delegate (self.tabBarController = ...) or if you use an xib make the IBOutlet connection from the UITabBarController to the app delegate in the xib.
You could add the UITabBarController to the app's window, and then add the FrontPage UIViewController on top of it. Once you remove the FrontPage from the window, the UITabBarController will already be present underneath it.
Related
In my iPhone project, I have a navigation view controller. In each view that is loaded by this controller, I am setting buttons in the UINavigationBar that are doing different things for each view.
However, I want to have the .rightBarButtonItem do exactly the same thing each time (namely, pop up a UIActionSheet). How can I centralize this code and not have to put it in every view controller?
I tried subclassing UINavigationController and setting the .rightBarButtonItem in this subclass' viewDidLoad. However, no button is displayed then. (But when I put the same code in a view controller loaded by the navigation controller, the button is displayed and works fine).
The code I am using to set the rightBarButtonItem is:
self.navigationItem.rightBarButtonItem = ...
Subclass all the UIViewControllers that are pushed onto that UINavigationController and add the same viewDidLoad code.
In the appdelagate, we have a UINavigationController and the view controllers as well. then in it we can initialize the navigation controller with the root view controller. And I understand why need them too.
However, in the sample code of my reference book(iPhone SDK Application Development, author: Jonathan Zdziarski), all view controller classes were added with a navigation controller as property, while they seem to be never used. So what is the meaning of having them as property in view controller classes?
e.g
#interface XYZViewController: UIViewController
{
UITextView *textView;
UIButton *button;
.....
.....
UINavigationController *navigationController;
}
-(void)...
.....
...
#end
One more question:
All UIViewController instances can have the property "navigationItem" once they are navigated. so what do this navigationItem refer to? does it refer to the navigation controller that is navigating the view controller?
UIViewController has navigationController property that is handled by the framework and it points to the parent UINavigationController if the view controller in question has one.
Check the documentation for more info:
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIViewController_Class/Reference/Reference.html
The same documentation will tell you that navigationItem is a UINavigationItem object that represents a view controller in the navigation bar. You can customise its appearance, like title, prompt, back button behaviour, etc.
That said, I have no idea why your book adds a navigationController property to UIViewController subclasses. It was added in iOS 2.0, a long time ago already... Anyway, you shouldn't need to add it, as it's provided in UIViewController class.
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
my app first viewController is UIViewController.
and when user click button firstView disappear and push UITabViewController
is it possible?
i can't find how to push UITabViewController from UIViewController.
UPDATE sorry, I misread TabVC for UITableViewController. Do you mean UITableViewController or UITabBarController? I'll leave my answer below anyways.
In this instance, it's usually best to have a UITabBarController be the root view object. Although it can be done, it's a messier implementation, in my opinion.
I would in fact make the UITabBarController the root and display the UIViewController modally from that UITabBarController on launch.
The user would be presented with the UIViewController and when they clicked the button, dismiss that modal view, revealing the UITabBarController.
Just use a UINavigationController.
Use the navigation controller to push the tableView as the second level in the hierarchy. As a bonus you'll get the back button for 'free' and you don't have to worry about delegates for getting back to the original UIViewController.
you may try this:
self.tabBarController.selectedViewController
= [self.tabBarController.viewControllers objectAtIndex:2];
it should work because selectedViewController property contains view of selected tab.
First of all you have view controller . And make Second view controller which contain tabbarcontroller . Now just push second view controller . And add tabbarcontroller's view as a subview to second view controller .
Hope you gets it ..
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.