Referencing view in tabbar app? - iphone

I have a tabbar based app and would like to reference one of three views. There are three tabs. When tab2 is clicked, tab2view is created. tab1view needs to reference tab2view so it can be pushed into view. tab2view can be pushed into view via tab2 or tab1view. How do I give tab1view a reference to tab2view?
tab1view will also need to create tab2view if it hasn't already been created from a tab click.

You don't push views with UITabBarControllers, you add View Controllers to an array that get displayed when the user clicks the appropriate tab bar item. If by "push" you mean "switch to tab" then you just need to set the "selectedIndex" property of your TabBarController.
But I don't understand this dependency you have where the second tab's view controller has to be created by the first. If you're not seeing your second tab view when you click on the second tab button, then it means you're doing something wrong in building the tab bar itself.
Regardless, all view controllers in your tab bar are accessible via the "viewControllers" array so getting the second one would be:
UIViewController *secondVC = [[myTabBarController viewControllers] objectAtIndex:1];

Related

Tab Bar mysteriously disappears?

Attached are two images. The first shows my current main.storyboard, and the second shows my problem when I run the app. I have a tab bar controller that has two tabs. On the first tab there is a button. When pressed, the button goes to another view controller with content. At the top is a Navigation bar with a back button. After viewing content, I press the back button, and am back on the original page with the button, but the tab bar is missing. I have seen a few answered questions, but it appears they made their tab bar in the view controller instead of the storyboard. Another says that I should never return to a previous view unless I use an unwind segue. Is this true? If so, how do I set up an unwind segue. If not, how do I fix this problem otherwise? Thank you.
http://i.stack.imgur.com/IYmX2.png
http://i.stack.imgur.com/7slt5.png
The problem is in the wiring of your ViewControllers. You have probably embedded your UITabBarController inside the UINavigationController and not the other way around.
A correct layout looks like this in Interface Builder :
To reproduce:
In Interface Builder drop a UITabBarController. This will come with 2 UIViewController's already wired in.
Pick one of the UIViewController's (let's call it VController1) and click on Editor / Embed in / Navigation Controller. This wires the VController1 to live inside a UINavigationController that is inside the UITabBarController
Add a 3rd UIViewController next to VController1 Let's call it VController3
Wire in a segue between VController1 and VController3, for example with a button.
I hope that's clear enough
Try Linking the button in your viewcontroller (other than the views of the tabbed bar controller) with the tabbed bar controller. Create a segue that links the button with the controller of the tabbed bar application

Present a viewcontroller inside a navigationcontroller from another tab in tabbed application

I have a tabbed application and each tab has a navigation controller with table views in it.
In one of the view from a tab, I want to present the first view controller of another tab.
My tabViewController.viewControllers has an array of navigation controllers for each tab.
I cant seem to present the view controller directly without accessing the navigation controller and I guess you cant present a navigation controller.
What am I doing wrong??
If I understood you correctly, you can access to your root controller something like that: [[tabViewController.viewControllers objectAtIndex:index] objectAtIndex:0], but I dont think you can display one view twice. So you still should recreate this view controller to display it in another tab as childViewController, for example

How to retain tab bar after modal segue?

I have 3 View controllers in a tab bar. (my 3 icon). I have another view controller that is accessible from one of the 3 via a button. I do not want this extra view controller to show on the tab bar though.
On clicking the button with a push segue nothing happens, with a modal segue it opens the new page, but the tab bar disappears. (Even though I created a relationship from this new view controller to the tab bar).
How do I get the tab bar to remain? I don't really want to set up a navigation controller between my one view and the other (not on the tab bar) because it's not really hierarchal content.
Is modal actually the right segue to use?
Does your views (the views of the 3 views controller) contain the tab bar? If not, you may try transiting from the view to the view of the extra view controller.
see +[UIView transitionFromView:toView:duration:options:completion:]
When you select a Modal segue, the new view is not added as part of the current TabController stack. That's why the tab bar is not visible when you go to this view, and it's why a Push segue does not work for you (you can't push a VC that's not part of the stack).
From the sounds of it, if you want the tab bar to remain visible/useful but don't want to add this VC to the tab bar, what you're really saying is that this VC is a sub-view of one of the original 3 VCs in the tab bar.
In which case you could manage instantiation of your "custom" VC from within one of these original VC's, and add it as a sub-view?
For example if you've got: Tab1, Tab2, Tab3 and ExtraView
in Tab2 VC you would init/alloc SubView and do: [self addSubView:ExtraView.view];
Unfortunately, of course this way you lose Segues, but unless you want to go ahead and set up Tab2 as nested NavigationController in Storyboard, I think that's your best bet.

Problem in adding more than 5 button in tab bar controller in iphone

Hello everybody i need your help.
I am making a tab bar based application in iphone. i have more than 5 button to show in tab bar. when i did it, five button displayed fifth button is more..... but when i clicked on more then more button came in a table view not in tab bar.
That's how it works. From the documentation (http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/TabBarControllers/TabBarControllers.html%23//apple_ref/doc/uid/TP40007457-CH102-SW2):
If you add more than five items to the
viewControllers property, the tab bar
controller automatically inserts a
special view controller (called the
More view controller) to handle the
display of the additional items. The
More view controller provides a custom
interface that lists the additional
view controllers in a table, which can
expand to accommodate any number of
view controllers. The More view
controller cannot be customized or
selected and does not appear in any of
the view controller lists managed by
the tab bar controller. For the most
part, it appears automatically when it
is needed and is separate from your
custom content. You can get a
reference to it though by accessing
the moreNavigationController property
of UITabBarController.
That is intended behavior and not an issue, if you read the viewController Programming guide you could have seen that right away: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007457

Tab bar navigation

I have made an application in which I have four tab bars. I have used the below code to go to the second view in a button's click method. It goes to the second view but the second view is not showing with tab bars. How can I fix this?
- (IBAction)Existinguser:(id)sender
{
ExistingUserViewController *existingUserViewController =
[[ExistingUserViewController alloc]
initWithNibName:#"ExistingUserViewController" bundle:nil];
[self presentModalViewController:existingUserViewController animated:YES];
[existingUserViewController release];
}
Presenting a view controller modally will show that view controller above all ther other UI elements (this includes the navigation bar and tab bar, but not the status bar).
If you want to show your "second view" as the view on the second tab, then you need to set the view controller you want to use as the second tab's view controller. That way when you press the second tab, the second view controller will be shown, and the second tab will be selected and visible.
I might be mistaken, but do you have a single tab bar with four tabs and you are looking for a way to change to the second tab? You can do this with the following code:
self.tabBarController.selectedIndex = 1;
btw the code you attached to your question is displaying a new model view controller above the current view controller. This is the reason no tabbar is shown.
If you are trying to create a navigation based app using tabbar, in IB, change the tab's viewcontroller to UINavigationController. You can then use the UINavController methods to navigate between views. In case you don't want to show the navbar, just set that property in IB.
Here's a good example of how you can use tab bar with navbar