Combining UITabBarController with UINavigationContoller - iphone

I am sure this is very simple, yet I am stuck...
I have created an application and added UITabViewController (dragged in from the library in Interface Builder. My application has 3 different views, clicking on appropriate tab brings the different view. So far so good.
I want to convert one of the views to be a UINavigationController: basically a table with the option to delete rows (so UINavigationController would need to have a button "Edit" on top).
I saw many samples which would do either 1 or 2, but not both.
How would I combine it, keeping in mind that I have used provided UITabViewController and did not added UITabBar directly to the view.
Thanks

If you are using Interface Builder, you should be able to just drag and drop a navigation controller into your tab bar controller as a child controller. The next tab bar item should be generated for it automatically from that.
You can also do this programatically by just creating however many UINavigationControllers you need in an array and assigning that to the uitabbarcontroller appropriately.

I actually don't like this method of combining the UINavigationController and UITabBarController since the tab bar controller must always be visible, which can be really confusing sometimes.
Instead, I recommend you make your own custom UITabBarController (Tab bar controller inside a navigation controller, or sharing a navigation root view) which you add to the navigation controller. I personally don't know why Apple didn't do this; hopefully this is the standard way in 4.0 :)

Related

Objective - C How to manage multiple views with View Controller iphone

I am new in developing iOS apps. I am trying to develop a multiple views app. My doubt is how to manage a multiple views app with View Controller, I mean, I do not want to use Navigation Controller nor Tab Controller.
My idea is to show a first View to choose the language, and after this, I want to show some different profiles in a table view. When you choose the profile, you get into a menu where you have some different functionalities (Once in this menu, I might use Navigation Controller).
My problem is that I don't know how to manage these two first views. I don't know if I have to declare them in the appDelegate, or if I can do it nesting one to other, I mean, I do the first view, and when I pressed the button, I declare the new view. Once in the new view, when I pressed a row in the table view, I make the another view.
I know it is a little bit confusing, so I hope you could understand it quite well.
EDIT:
I want to clarify that I am not using storyboards. My main doubt is what to do with all de view controllers, Do I have to declare all of them in the appDelegate? or Can I declare each view in every controller?
If you are using storyboards, you can use Segue's to navigate between the views, so you would show your first view, then you could tie a button to the next view (by control dragging in storyboard). If you want to transition programmatically you can use the performSegueWithIdentifier method. You could use the same approach to get from your tableViewController to your next viewController by using the performSegueWithIdentifier method from within the tableViewController's didSelectRowAtIndexPath delegate method (i.e. when a user taps a cell).
That should get you started. Good luck!
EDIT:
You really should be using storyboards. It's the way to do things these days. If you refuse, then the best approach is to create a container view controller that manages your "children" view controllers. You can find information on doing this, as well as the methods needed to present/remove child view controllers here:
Custom Container View Controllers
You can use navigation controller with "hidden" property.
self.navController.navigationBarHidden = YES;
If you want to have two different views and transition between them, you will want to use UIViewControllers presented modally. Here is Apple's Guide to this.

UITabBarController functionality with UITabBar

I'm making an app with interface builder using storyboarding.
I want to have a tab bar where no item is selected. This can be accomplished by setting
TabBar.SelectedItem = null;
But if you try to do that, you get the following error:
'Directly modifying a tab bar managed by a tab bar controller is not allowed.'
So I can't use the standard UITabBarController. I've created a custom UIViewController, and added a UITabBar. Switching between tabs is working fine, and having no selection is also working as it should.
But I have no idea how to show my other view controllers from my custom view controller with the tab bar. Remember that I'm using interfacebuilder, so I can't just create my view controllers in code as new objects and add them to the view. (as suggested in UITabBar funcionality without UITabBarController)
So how do I show my own views without using the UITabBarViewController?
Edit: Still haven't found a solution, but I did a hacky fix. Simple create an other tab bar and place it on top of the original tab bar. Listen to those events and use SelectedIndex to change the view displayed. Then add some function that will select / deselect the items on your own tab bar.
In fact, even if you design your others UIViewControllers from IB, you can instantiate them from code. You'll probably have to play a bit with frame and autoresizing properties to make them fit the part of your main view you want them to display inside, but it's possible.
So, knowing that, a simple solution is to create a simple UIView (we'll call it 'tabFrame') in your main UIViewController, which fill the screen from the top of your UITabBar to the top of the screen; instantiate the UIViewController corresponding to your tabs and add their view as subview of tabFrame. Now you just have to catch item selection from tabbar to hide or show the desired subviews.
Hope I'm clear enough, else don't hesitate to question!
EDIT: pointed out this morning that in storyboarding context, you can effectively instantiate viewControllers / scene from code, but for not loosing designer settings it must NOT be done through directly calling their constructors, but through StoryBoard.InstantiateViewController("vc_identifier") calls, after having set identifiers to VCs in storyboard editor.
See http://docs.xamarin.com/ios/recipes/General/Storyboard/Storyboard_a_TableView for example

Tabbar with different Data

I am trying to develope an iPhone App for 3 months.
I found everything myself in books or the internet. Now I have a problem that I am not able to solve myself.
I would like to develope a tabbar application with 3 tabs.
In each tab is a navigation controller with a tableview.
The tableview loads the data from an XML file on the web. The difference between each tab is only the difference XML-url. The tableview and function should everywhere the same.
What have I done?
Created a tabbar application
Put 3 Navigation Controller in the Tab Bar Controller in the MainWindow.xib
Every View in each Navigation Controller points to the same "TableView" class
Now it loads on every tab the same tableview. But I just want to change the XML-URL which is loaded. But I dont know how to implementate this.
I hope that somebody can give me a hint? Thank you!
Are you sure you need a Tab Bar? You could just add an additional level of navigation on top for the sources. So your navigation controller stack would be like
UINavigationController -> SourceViewController -> ListViewController -> rest of your navigation stack.
ListViewController is a subclass of a UITableViewController which is passed the source url based on selection from SourceViewController which can be a subclass of UITableViewController too. This will save you of the repetition you are trying to avoid and is more likely a better option for the thing you need.
Now if you insist on using a Tab Bar, your stack will be more like –
UITabBarController which will have three instances of UINavigationController each with its own instance of ListViewController which like before will be initialized using a source url.
Now it may be smarter to reduce it to a single ListViewController and attaching all the navigation controllers to it. You can do this using the -tabBarController:didSelectViewController: method in the tab bar delegate. On every tab change/call, you clear the current cache that is providing data to the table view and load the appropriate cache based on the source XML of that tab.
Usually state is preserved on tab changes but using this structure you will have to do additional work to get that.

Show ToolBar over TabBar

In my app I would like to replace the TabBar with a ToolBar under certain conditions, similar to what happens in the Photos App when a user places it in selections mode (A toolbar with share copy, etc, buttons appear over the tab bar). How can I achieve this please?
This can be achieved by creating a new toolbar, assigning it an appropriate frame and adding it to self.tabBarController.view
I'm assuming your root view controller is a UITabBarController. Sometimes using the canned "Root" UIViewControllers is more of a hindrance than a help, especially if you want a highly custom look that does not fit into the paradigm of what the canned controllers offer. There's no reason you have to use them -- you could write your own, and do your own transition between your sub-UIViewController views onto the screen. You can use the UITabBar without the UITabBarController in your own custom UIViewController subclass, then you don't end up fighting the behavior of UITabBarController. Writing your own root ViewController can be very instructive as well -- you learn about all the things a root ViewController must do to manage the sub-ViewControllers.

Is this a valid structure of an app

I have the following structure in my app, is this a correct/valid way of doing it?
UINavigationController attached to the window, the rootcontroller in this navigationcontroller is a UIViewController that presents a tableview. When a user taps one of the rows a UITabBarController is pushed on the stack.
This works, however I began to be unsure when I read this:
Because the UITabBarController class
inherits from the UIViewController
class, tab bar controllers have their
own view that is accessible through
the view property. When deploying a
tab bar interface, you must install
this view as the root of your window.
Unlike other view controllers, a tab
bar interface should never be
installed as a child of another view
controller.
This is not recommended, but it should be OK. The aweful Wordpress app also does this. This depends on the design of your app.
I'm not shure about Apple's approval.
The reason why this is not recommended (and thus might not get approved - now or at a later point!) is user confusion.
Users are used to regard the tab bar as top-level navigation. So if dig down using the table and navigation, and then getting a UITabBar, this is horrible for navigation as the user doesn't know what to expect.
The solution here, of course depending on the use case, is a "switch" in the navigation bar or a toolbar. UISegmentedControl would be a natural choice.