UITabBarController tab nonfunctional - iphone

Scenario: UITabBarController has three tabs corresponding to each of three view controllers which are successfully instantiated / initialized.
On launch, the second tab is selected automatically, and one can toggle back and forth between the second and third tabs.
The first tab, however, does not respond to taps. One cannot switch to the first tab.
All three VCs are present in memory and responding to messages. All three VCs are instantiated the same way:
//Initialize the tab bar view controllers
vc1 = [[VC1 alloc] init];
vc2 = [[VC2 alloc] init];
vc3 = [[VC3 alloc] init];
tabCon = [[UITabBarController alloc] init];
//Install the tab bar
NSArray *viewControllers = [NSArray arrayWithObjects:vc1,vc2,vc3,nil];
[tabCon setViewControllers:viewControllers];
[vc1 release];
[vc2 release];
[vc3 release];
Any thoughts on a likely cause would be very much appreciated.

Well, I'm afraid the solution won't really be helpful to anyone that runs into a similar issue.
Turns out I had a conditional I'd forgotten to disable that forced the tabbarcontroller to flip to tab 1 if certain conditions were not met in tab 0.

Related

No effect on setViewController:animiated:?

Basically I have
ViewControllerA *aVC = [[ViewControllerA alloc] init];
ViewControllerB *bVC = [[ViewControllerB alloc] init];
UITabBarController *tabBarVC = [[UITabBarController alloc] init];
[tabBarVC setViewControllers:[[NSArray alloc] initWithObjects:aVC, bVC, nil] animated:YES];
Now I can see the two tabs on the tabBarController but when I switch from one tab to another, I can't see any effects, neither on simulator or on real device. From the documentation I should be able to see fading right? Did I miss anything?
If you pass YES to setViewControllers:animated:, UITabBarController will animate the insertion of the the new tab bar items in the tab bar. It doesn't animate the transition between view controllers if the user then switches from one tab to another.

Single tab in UITabBar does not contain a UINavigationBar

I'm having a really strange issue. I've written an app with five tabs in a UITabBar. When I set the TabBarController's viewControllers property, I set it with five UINavigationControllers, so that each tab will have a UINavigationController within it.
Four of the tabs have it working perfectly. The navigation bar is there when I launch and switch to that tab. However, one of the tabs does not contain the UINavigationBar as I expected it to, and I can't understand why, because I initialized it exactly the same way I initialized all the others.
Here's some sample code from the AppDelegate.m file of initializing the individual view controllers:
SpotFilterViewController *spotList = [[SpotFilterViewController alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController:spotList];
[tabs addObject:navigationController];
[navigationController release];
[spotList release];
MySpotViewController *mySpot = [[MySpotViewController alloc] initWithSpot:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:mySpot];
[tabs addObject:mySpot];
[navigationController release];
[mySpot release];
Note: navigationController was declared above.
Anyone else run into this problem before? Or anyone have any idea why this might be happening? Any help is much appreciated. Thanks!
The problem is that you are doing this:
[tabs addObject:mySpot];
instead of this:
[tabs addObject:navigationController];

How to add a 2nd view as a Tab Bar View (iPhone SDK)

So before I've managed to work with TabBarViewControllers and create an application using them. However every time I do so the view acts as my main view. This time around I want my TabBarView to be my second view in my application
E.g
First window has a bunch of buttons, when I click one of these buttons I want the second view to show up. This view includes a TabBarViewController.
The farthest I've gotten is to have the button show a view but for some reason it won't show my TabBar view!
Here's the code for my button
- (IBAction)showEvents:(id)sender {
EventsViewController *controller = [[EventsViewController alloc] initWithNibName:#"EventsView" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
}
Any of you guys able to help?
Can't you just in the EventsViewController add the following code in viewDidLoad:
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = [NSArray arrayWithObjects: vc1, vc2, ..., nil];
Anyway, I found a solution and it was actually quite simple. After creating the Outlet for the TabBarController and linking it together with File's Owner all I had to do was add
self.view = tabViewController.view;
On the viewDidLoad method

Tab bar appearing below the edge of the screen

I'm creating an application that, when the user selects a project in a table, displays a view with a tab bar at the bottom. I'm using this code:
- (id)init
{
[super initWithNibName:nil bundle:nil];
tabController = [[UITabBarController alloc] init];
// Create all view controllers to be included in the tab bar
SummaryViewController *summaryController = [[SummaryViewController alloc] init];
ImagesViewController *imagesController = [[ImagesViewController alloc] init];
// Make an array containing the view controllers
NSArray *viewControllers = [NSArray arrayWithObjects:summaryController, imagesController, nil];
[summaryController release];
[imagesController release];
// Attach them to the tab bar controller
[tabController setViewControllers:viewControllers];
[self.view addSubview:tabController.view];
return self;
}
With the end result being the tab bar at the bottom appearing cut off around half its height. I'm guessing it's somehow related to the navigation controller at the top (link to image).
Any help in solving this mystery would be greatly appreciated!
I believe the problem here is that you're adding the UITabBarController as a subview of another UIViewController. UITabBarController descends directly from UIViewController.
Instead of creating this view controller to hold it, you should just create the tab bar controller, configure it and push that onto your stack.

Custom UITabBarController

I want to customize the look and feel of the tab bar of a UITabBarController. I want to change the colors, the way the icon looks when they are selected, and also, most important of all, I want to reduce the size of the custom toolbar.
My approaches for this and the hurdles in it are:
A) The first solution which came to my mind was to create my own viewController which will act like a UITabBarController with buttons in the bottom and add this viewController to the window. Once when user taps a button at the bottom, swap the view in the viewable area with the new viewController's which corresponds to the button now tapped by user.
The problem with this strategy is: since I swap view's the corresponding viewControllers will not get these messages:
viewWillAppear
viewWillDisappear
viewDidAppear
viewDidDisappear
And all the rotation events
B) I could have used the accepted answer's approach in this thread:
Custom UITabBarController Problems with View Controllers and Views
But my tabBar's height is not the same as the default.
Due to the cited reasons above, I cannot use those approaches.
Having said this, I have no special requirement of More tab. I will be having only 5 tabs which will be displayed by the tab bar and hence the re-ordering of tab bar items is out of scope.
Awaiting suggestions and ideas.
I have never attempted something like this but as I see it, you are supposed to send those messages to your child view controllers manually.
It shouldn't be problem to send -viewWill/Did(Dis)Appear to the right controller at the appropriate moment. This is what UITabBarController does, too.
As for rotation events:
In shouldAutorotateToInterfaceOrientation:, forward this message to your child controllers and set your return value depending on their return values (UITabBarController only returns YES if all its child controllers return YES for the requested orientation).
Forward willRotateToInterfaceOrientation:duration:, didRotateFromInterfaceOrientation: and willAnimateRotationToInterfaceOrientation:duration: to the child controllers (at least to the currently visible one) when you receive them.
If you have set the autoresizing masks of your child controllers' views correctly, they you rotate and resize correctly when the system rotates your custom tab bar controller's view. (At least I think that's how it should work.)
Again, I'm not sure if this will work.
You can implement the following code for the creating the custom tab bar in that use to images using the CGRect make.further code is use for the creating the custom tab bar
-(void)applicationDidFinishLaunching:(UIApplication *)application {
// Add the tab bar controller's current view as a subview of the window
tabBarController.delegate = self;
tabBarController = [[UITabBarController alloc] init];
mainDashBoard = [[DashBoard alloc] initWithNibName:#"DashBoard" bundle:nil];
mainSearchView = [[SearchView alloc] initWithNibName:#"SearchView" bundle:nil];
mainMoreView = [[MoreView alloc] initWithNibName:#"MoreView" bundle:nil];
UINavigationController *nvCtr0 = [[[UINavigationController alloc] init] autorelease];
UINavigationController *nvCtr1 = [[[UINavigationController alloc] initWithRootViewController:mainDashBoard] autorelease];
UINavigationController *nvCtr2 = [[[UINavigationController alloc] initWithRootViewController:mainSearchView] autorelease];
UINavigationController *nvCtr3 = [[[UINavigationController alloc] initWithRootViewController:mainMoreView] autorelease];
UINavigationController *nvCtr4 = [[[UINavigationController alloc] init] autorelease];//[[[UINavigationController alloc] initWithRootViewController:nil] autorelease];
tabBarController.viewControllers = [NSArray arrayWithObjects:nvCtr0,nvCtr1,nvCtr2,nvCtr3,nvCtr4,nil];
nvCtr0.tabBarItem.enabled = NO;
nvCtr4.tabBarItem.enabled = NO;
[window tabBarController.view];
}