My app requires one set of tabs on the initial view, the last tab item is reserved for an in-app purchase once the user selects. However, once the user makes the in-app purchase I would like a new set of tabs to appear. I would like for the user to be able to switch back and forward between the free part of the app and the in-app purchase part of the app with different tab bars. For example:
"TabBar1" to have "TabItem 1", "TabItem 2", "TabItem 3", and "TabItem 4" for my Free App, when user selects "TabItem 4" ...a welcome or in-app purchase screen will appear. If user makes the in-app purchase, "TabBar2" appears with "TabItem 1", "TabItem 5", "TabItem 6", and "TabItem4". "TabItem1" will bring you back to Free part of app and "TabBar1" when selected again. Hope I didnt confuse...How do you accomplish this? Thanks for the help.
I forgot to add that this Tabbar is to be combined with a Navigation controller as well.
you can change the views of root tabbarcontroller anytime you want, also you can change tabbaritems title & icons. Here's an example:
MyAppDelegate *appController = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
// Setting 1st tab + view + icon
ViewController1 *viewController1 = [[ViewController1 alloc] initWithNibName:#"ViewController1" bundle:nil];
favoritesController.title = #"Tab1 Title";
UINavigationController *navigationTab1Controller = [[[UINavigationController alloc] initWithRootViewController: viewController1] autorelease];
UITabBarItem *anItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0] autorelease];
navigationTab1Controller.tabBarItem = anItem;
// Setting 2st tab + view + icon
ViewController2 *viewController2 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
searchController.title = #"Tab2 Title";
UINavigationController *navigationTab2Controller = [[[UINavigationController alloc] initWithRootViewController:searchController] autorelease];
UITabBarItem *anItem1 = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:1] autorelease];
navigationTab2Controller.tabBarItem = anItem1;
// Now setting the array of tab views, each one attached to its navigation controller
NSArray *array = [[NSArray alloc] initWithObjects:self.navigationController, navigationTab1Controller, navigationTab2Controller, nil];
[appController.tabBarController setViewControllers:array animated:NO];
appController.tabBarController.selectedViewController = self.navigationController;
UITabBarItem *anItem2 = [[[UITabBarItem alloc] initWithTitle:#"Tab3 Title" image:[appController thumbnailImage:#"image"] tag:2] autorelease];
self.navigationController.tabBarItem = anItem2;
I'm changing the set of views and tabs, depending of the state of my application. Hopefully it helps
EDIT: function thumbnailImage is a function I wrote for caching images and avoid memory leaks, you can use imageNamed instead or other technique that retrieves an image from a bundle.
While this might be possible, I would highly suggest against it from a User Experience perspective. Swapping a core piece of the navigational UI out from under the users nose is bound to confuse some users and it not really needed in this situation.
There are plenty of other ways to give feedback to the user, and plenty of ways to handle in-app purchases and I highly recommend doing some mockups of methods that could not potentially confuse the user.
Related
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.
I created a view based app. In a view Controller class I created a tab bar Dynamically. The App is running fine, but I am having a problem with handling a push-notification. While Push-notification sent means I received the push alert, I want to know how to show selected index 3 of my Tab bar.
in the view based application after 2 class i create this tabbar dynamically.
tabbar1 = [[UITabBarController alloc] init];
tab_obj1 = [[First alloc] initWithNibName:#"First" bundle:nil];
UINavigationController *tabItem1 = [[[UINavigationController alloc] initWithRootViewController: tab_obj1] autorelease];
tabItem1.title=#"First";
tabItem1.tabBarItem.image=[UIImage imageNamed:#"FirstIcon.png"];
tab_obj2 = [[Second alloc] initWithNibName:#"Second" bundle:nil];
UINavigationController *tabItem2 = [[[UINavigationController alloc] initWithRootViewController: tab_obj2] autorelease];
tabItem2.title=#"Second";
tabItem2.tabBarItem.image=[UIImage imageNamed:#"SecondSelc.png"];
tab_obj3 = [[Third alloc] initWithNibName:#"Third" bundle:nil];
UINavigationController *tabItem3 = [[[UINavigationController alloc] initWithRootViewController: tab_obj3] autorelease];
tabItem3.title=#"Third";
tabItem3.tabBarItem.image=[UIImage imageNamed:#"ThirdIcon.png"];
tab_obj4 = [[Fourth alloc] initWithNibName:#"Fourth" bundle:nil];
Write your code to select tabbar index in the below method
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// Notification code here
}
Above Method calls everytime notification comes, so you can write your code here for the selection of tabbar index.
Your question has nothing to do with Push Notification...
To show any given tab of your TabBarController, you can do something like this:
tabBarController.selectedIndex = 3;
where tabBarController is a pointer to your application's tab bar controller object.
There are special considerations for changing selectedIndex to a value that represents the More controller. Check the documentation for UITabBarController and the selectedIndex property for the details.
Hi Developers, Thanks for responding me.I will show that badge value inside the tabBar tab.
I create tabBar controls again in didReceiveRemoteNotification method and in non-active state app from this tabbarcontroller_obj.tabBarItem.badgeValue=#"3" Like this I handle the notification badge value inside the application.
Hihi all,
I am trying to make use of tabbar control in my iphone application, I have a few enquiries regarding the control.
If i create a tabbar template project, in my application delegate, it loads all the 5 tab controllers during the launch of the application, will this cause any inefficiency of the memory usage?
Can I actually drag the tabbar control into each of my screen, and manually switch between screens with [self presentedViewController..] and [self dismissModalViewControllerAnimated...] methods?
What is the most efficient way of using tabbar in iphone app?
Thanks in advance!
:)
Even though I'm not sure what 'most efficient' means in your context, I'll try to explain 3. with explaining what I usually do when it comes to typical tabbar apps:
I don't go with the sample project, because there's so much magic (to me) in all that IB stuff (and I had hard experiences in trying, to combine tabbar controllers and navigation controllers).
I just set up a simple project, get rid of all IB stuff and do something like that in the app delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSMutableArray *cons = [[NSMutableArray alloc ]init];
viewController = [[UITabBarController alloc] init];
int i = 0;
UIViewController *firstController = [[SomeViewViewControllerClazz alloc] init];
firstController = [[UITabBarItem alloc]initWithTitle:#"Een" image:nil tag:i];
[cons addObject:firstController];
[firstController release];
i++;
UIViewController *secondController = [[AnotherViewControllerClazz alloc] init];
secondController = [[UITabBarItem alloc]initWithTitle:#"Twej" image:nil tag:i];
[cons addObject:secondController];
[secondController release];
i++;
UIViewController *thirdController = [[WhateverViewControllerClazz alloc] init];
thirdController = [[UITabBarItem alloc]initWithTitle:#"Drej" image:nil tag:i];
[cons addObject:thirdController];
[thirdController release];
i++;
viewController.viewControllers = cons;
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
That way I've maximum freedom to do whatever I want with the controllers but also have the built in power of tabbars.
1.: That way I never had memory issues even though I load controllers right at the beginning.
2.: If the tabbar idea fits your app, use it as iOs provides it.
The answer of your enquiries are:
No, this will not cause any inefficiency of the memory usage. But you should release tab bar controller
You may be do this, But it is not good practice and when you call presentedViewController tab will be vanished (sorry for inappropriate term).
The most efficient way of using tabbar in iphone app is take a tabbar controller and add that tabBar view.
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.
I made two applications that each one of them is tabbar based.
Now I want to combine them to one app that will be struct like that:
-Main menu with 2 buttones.
- button 1: tab bar app no 1.
- button 2: tab bar app no 2.
from each tab bar app, I want an Home button on the left side of the nav bar that will take me to the main menu.
I found this link http://www.pushplay.net/blog_detail.php?id=27 but it's not good to me..
I will be happy if you will able to post some simple code for my problem..
Thanks.
App's 1 & 2 need to be based around viewcontrollers, each of which has a tabbar. The root windows can then just alloc/init and then [self.navigationController pushViewController:viewController animated:YES]; to launch the tabbar controller.
If you have relied on IB to build your tabbar applications, its quite difficult to translate them into view controllers. I create my tabbars programatically (i just find it easier) like this
tabBarController = [[UITabBarController alloc] init]; // creates your tab bar so you can add everything else to it
searchTableViewController = [[SearchTableViewController alloc] init];
UINavigationController *searchTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchTableViewController] autorelease];
[searchTableViewController release];
searchMapViewController = [[SearchMapViewController alloc] init];
UINavigationController *mapTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchMapViewController] autorelease];
[searchMapViewController release];
atestViewController = [[AboutTableViewController alloc] init];
UINavigationController *AboutNavController = [[[UINavigationController alloc] initWithRootViewController:atestViewController] autorelease];
[atestViewController release];
tabBarController.viewControllers = [NSArray arrayWithObjects:searchTableNavController, mapTableNavController, AboutNavController, nil];
[self.view addSubview:tabBarController.view];