i am working on a chat project in which i have to use a UITabBar. I am using storyboard in this project but according to requirement i added custom TabBar in project to mount it on the top of the view.
Now the problem is Custom TabBar is showing well on the top of view but when i click on the tabs it only shows black screen instead of showing the ViewControllers.
i am sharing my code please suggest me the solution of it.
my .h file
#interface TabBar : UITabBarController
{
}
#property(strong,nonatomic) UITabBarController *tabbarcontroller;
#property(strong,nonatomic) ChatListVC *chatlist;
#property(strong,nonatomic) ContactListVc *contactlist;
#property(strong,nonatomic) FindfriendsVC *findfriends;
#end
my .m file
#implementation TabBar
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// self.navigationItem.hidesBackButton=YES;
self.title = #"Chat Home Page";
self.navigationController.navigationBar.backgroundColor = [UIColor blueColor];
_chatlist = [ChatListVC new];
_contactlist = [ContactListVc new];
_findfriends = [FindfriendsVC new]; //initWithNibName:#"FindfriendsVC" bundle:nil];//[FindfriendsVC new];
self.tabbarcontroller = [[UITabBarController alloc]init];
self.viewControllers = [NSArray arrayWithObjects:_chatlist,_contactlist,_findfriends, nil];
//self.navigationController.navigationBar.frame.size.height;
//UITabBar *tabBar = self.tabBarController.tabBar;
//CGFloat topBarOffset = self.topLayoutGuide.length;
self.tabBar.frame =CGRectMake(0,44,self.view.frame.size.width,50);
UITabBarItem *item0 = [self.tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [self.tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [self.tabBar.items objectAtIndex:2];
item0.title = #"Chat List";
item1.title = #"Contacts";
item2.title = #"Find Friends";
[item0 setFinishedSelectedImage:[UIImage imageNamed:#"chatlist.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"chatlist.png"]];
[item1 setFinishedSelectedImage:[UIImage imageNamed:#"contacts.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"contacts.png"]];
[item2 setFinishedSelectedImage:[UIImage imageNamed:#"findfriends.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"findfriends.png"]];
}
snapshot of the output is
It looks like your view controllers aren't being initialised properly.
If your view controllers are all in the Storyboard, try replacing
_chatlist = [ChatListVC new];
_contactlist = [ContactListVc new];
_findfriends = [FindfriendsVC new];
with:
_chatlist = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"ChatListIdentifier"];
_contactlist = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"ContactListIdentifier"];
_findfriends = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"FindfriendsIdentifier"];
Where the identifier string is your own identifier that you have set up in the Storyboard.
Related
I have embedded a UITabBarController inside a UINavigationController. The UITabBarController contains 3 different tabs which leads to 3 different UIViewControllers which displays UITableView. I implemented all these through storyboard. In the first UIViewController, I have implemented a UISearchController for the UITableView programatically which is working. The View turns black when I search for a particular cell and then if I switch tabs.
I believe that the issue has some relation to SearchController because before including the SearchController, I didn't have any issues.
I have gone through few other questions in here, but none could solve my issue.
Edited :
Below is my code related to SearchController.
#interface
#property (nonatomic, strong) UISearchController *searchController;
#property BOOL searchControllerWasActive;
#property BOOL searchControllerSearchFieldWasFirstResponder;
#implementation
viewDidAppear()
self.searchController = [[UISearchController alloc]initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
[self.searchController.searchBar sizeToFit];
self.tblContactsTable.tableHeaderView = self.searchController.searchBar;
self.searchController.delegate = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.delegate = self;
self.definesPresentationContext = YES;
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
//reloads table view according to what is searched.
-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
self.searchController.searchBar.showsCancelButton = NO;
UITabBarController should be the top most element on window from your storyboard/code and you can add the Navigation Controllers and View Controllers to UITabBarController view controllers.
https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UITabBarController_Class/index.html
use this sample code it will surely help you here chatlist, contactlist and findfriends are 3 UIViewControllers
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// self.navigationItem.hidesBackButton=YES;
self.navigationController.navigationBar.backgroundColor = [UIColor blueColor];
_chatlist = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"ChatListVC"];
_contactlist = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"ContactListVc"];
_findfriends = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"FindfriendsVC"];
self.tabbarcontroller = [[UITabBarController alloc]init];
self.viewControllers = [NSArray arrayWithObjects:_chatlist,_contactlist,_findfriends, nil];
self.tabBar.frame =CGRectMake(0,44,self.view.frame.size.width,50);
UITabBarItem *item0 = [self.tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [self.tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [self.tabBar.items objectAtIndex:2];
item0.title = #"Chat List";
item1.title = #"Contacts";
item2.title = #"Find Friends";
[item0 setFinishedSelectedImage:[UIImage imageNamed:#"chatlist.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"chatlist.png"]];
[item1 setFinishedSelectedImage:[UIImage imageNamed:#"contacts.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"contacts.png"]];
[item2 setFinishedSelectedImage:[UIImage imageNamed:#"findfriends.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"findfriends.png"]];
}
Figured out the answer myself. I don't know if its the exact right way of doing it but now the App seems working.
I place my UITabBarController as the Initial View and separate UINavigationControllers for each tabs.
I updated my version of XCode and now I get the following error:
*application windows are expected to have a root view controller*
I read that the error is because I have no RootViewController assigned .
The problem is that I have multiple subviews and any is a main view.
Example:
// Add the view controller's view to the window and display.
[window addSubview:infoTabViewController.view];
[window addSubview:shareTabViewController.view];
[window addSubview:tabViewController.view];
[window addSubview:mainTabViewController.view];
How you could assign these subviews to a RootViewController?
Thanks.
Firstly you Write in appdelegate.m to set root view controller
- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
self.logviewController = [[LoginViewController alloc]init];
self.navigationController = [[UINavigationController alloc]initWithRootViewController:self.logviewController];
[self.window setRootViewController: self.navigationController];
[self.window makeKeyAndVisible];
return YES;
}
after that add tabbar controller and write code in view did load
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationItem.leftBarButtonItem=nil;
self.navigationItem.hidesBackButton=YES;
self.view.backgroundColor = [UIColor whiteColor];
self.title = #"Welcome To MyConnect";
_friendviewcontroller = [FriendsViewController new];
_homeviewcontroller = [HomePageViewController new];
_notifviewcontroller = [NotificationViewController new];
_messageviewcontroller = [MessagesViewController new];
self.tabbarcontroller = [[UITabBarController alloc]init];
self.viewControllers = [NSArray arrayWithObjects:_homeviewcontroller,_messageviewcontroller,_friendviewcontroller,_notifviewcontroller, nil];
//UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [self.tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [self.tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [self.tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [self.tabBar.items objectAtIndex:3];
[item0 setFinishedSelectedImage:[UIImage imageNamed:#"blue-home-icon.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"home_2.png"]];
[item1 setFinishedSelectedImage:[UIImage imageNamed:#"email-icon-env.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"message_2.png"]];
[item2 setFinishedSelectedImage:[UIImage imageNamed:#"friendreq_icon.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"friendreq_2.jpg"]];
[item3 setFinishedSelectedImage:[UIImage imageNamed:#"notification_icon.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"bell-512.png"]];
UIImage *img1=[UIImage imageNamed:#"menu-2-128.png"];
CGRect frameimg1 = CGRectMake(340, 0, 35,35);
UIButton *signOut=[[UIButton alloc]initWithFrame:frameimg1];
[signOut setBackgroundImage:img1 forState:UIControlStateNormal];
[signOut addTarget:self action:#selector(collectionmenutwo:)forControlEvents:UIControlEventTouchUpInside];
[signOut setShowsTouchWhenHighlighted:YES];
UIBarButtonItem *barButton=[[UIBarButtonItem alloc]initWithCustomView:signOut];
self.navigationItem.rightBarButtonItem=barButton;
item0.title = #"Home";
item1.title = #"Messages";
item2.title = #"Friends Requests";
item3.title = #"Notification";
}
take a UITabBarController and make this rootViewController.
and add all of your subview on this TabBarController.
code sample
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
UITabBarController *tabBarController = [[UITabBarController alloc]init];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
FirstViewController *firstViewController = [storyboard instantiateViewControllerWithIdentifier:#"FirstViewController"];
SecondViewController *secondViewController = [storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
tabBarController.viewControllers = #[firstViewController,secondViewController];
[self.window setRootViewController: tabBarController];
[self.window makeKeyAndVisible];
But don't add NavigationController
I'm trying to change views within an app I am editing the code for. But the navigation bar doesn't seem to update in specific instances when presenting a new viewcontroller. Right now the behavior looks like this:
I navigate to a tableviewcontroller by clicking on a tab in the tabbar,
then I navigate to a viewcontroller from this tableviewcontroller using:
settingsController = [SettingsController create];
[self.navigationController pushViewController: settingsController animated: YES];
which I believe calls this code:
+(id)create
{
SettingsController*settings = [[SettingsController alloc] init];
NSBundle*bundle = [NSBundle bundleForClass: [SettingsController class]];
[bundle loadNibNamed: #"SettingsController" owner: settings options: NULL];
settings.view.frame = CGRectMake(0, 0, 320, 411);
settings.title = #"Settings";
return settings;
}
Then from there I navigate to another view controller using:
SearchViewController*searchView;
searchView = [[SearchViewController alloc] initWithNibName:#"SearchView" bundle: [NSBundle mainBundle]];
[self presentViewController:searchView animated:YES completion:nil];
and this is where the behavior starts getting buggy, the navigation bar doesnt update to the change in the view controller. I didn't write this code but it has been giving me a headache trying to clean it up.
If you are using a navigationController then you shouldn't call
[self presentViewController:searchView animated:YES completion:nil];.
You should use
[self.navigationController pushViewController:searchView animated:YES];
Also, it would be better to use the standard in-built function to initialize a new view controller.
SettingsController*settings = [[SettingsController alloc] initWithNibName:#"SettingsController" bundle:nil];
[self.navigationController pushViewController:settings animated:YES];
and then use the default method in the view controller.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = #"Settings";
//other view changes.
}
return self;
}
See this example for the way of initializing tabbarcontroller with navigation controller
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *viewController1, *viewController2,*viewController3;
viewController1 = [[ViewController alloc] init];
viewController2 = [[FormStatusViewController alloc] initWithNibName:#"FormStatusViewController" bundle:nil];
viewController3 = [[DocumentsViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController *nav1 =[[UINavigationController alloc] initWithRootViewController:viewController2];
UINavigationController *nav2 =[[UINavigationController alloc] initWithRootViewController:viewController3];
nav.navigationBarHidden=YES;
nav1.navigationBarHidden=YES;
nav2.navigationBarHidden=YES;
NSArray *viewsArray = [[NSArray alloc] initWithObjects:nav,nav1,nav2, nil];
self.formTabBar= [[UITabBarController alloc] init];
[self.formTabBar setViewControllers:viewsArray];
UITabBar *tabBar = self.formTabBar.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
tabBarItem1.title = #"FORM";
tabBarItem2.title = #"STATUS";
tabBarItem3.title = #"DOCUMENTS";
UIImage *tabBackground = [[UIImage imageNamed:#"tab_bg.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:#"form.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"form_h.png"]];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:#"status.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"status_h.png"]];
[tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:#"documents.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"documents_h.png"]];
} else {
tabBarItem1.selectedImage = [[UIImage imageNamed:#"form_h.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem1.image = [[UIImage imageNamed:#"form.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem2.selectedImage = [[UIImage imageNamed:#"status_h.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem2.image = [[UIImage imageNamed:#"status.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem3.selectedImage = [[UIImage imageNamed:#"documents_h.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem3.image = [[UIImage imageNamed:#"documents.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
}
[[UITabBar appearance] setSelectionIndicatorImage:
[UIImage imageNamed:#"tab_select_indicator.png"]];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
nil] forState:UIControlStateHighlighted];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.formTabBar;
[self.window makeKeyAndVisible];
return YES;
}
Now in your view controller suppose the firstviewcontroller in first tab you want to navigate to another view controller in that tab then use below code
SearchViewcontroller *searchView =[[SearchViewcontroller alloc]init];
[self.navigationController pushViewController:searchView animated:YES];
I have noticed that my GoogleMap stopped working in the sense that it has become inactive after first touch. This got me thinking, so I decided to create a new project with the same code to check to see if it was the code and shows that its not my GoogleMaps code. I think it has to do with how I set up my Navigation Bar and Tab Bar.
This is what I have. I have an initial ViewController inside a NavigationController. This view controller does many things, one of which is push view controllers. I have a button that pushes a UITabBarController onto the NavigationController stack. I have created a UITabBarController inside storyboard and gave that controller a StoryboardID: GRxTabBarViewController. GRxTabBarViewController has 4 view controllers, PricesViewController, SavingsViewController, InfoViewController, and MapsViewController.
I then created the header and implementation files of these controllers. This is what I have in my initial view controller to push this tab bar controller and tab bars.
-(void)pushTabBar
{
UIStoryboard *iPhoneStoryBoard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil];
GRxTabBarViewController *tabViewController = (GRxTabBarViewController*) [iPhoneStoryBoard instantiateViewControllerWithIdentifier:#"GRxTabBarViewController"];
PricesViewController *pricesController = [tabViewController.viewControllers objectAtIndex:0];
SavingsViewController *savingsController = [tabViewController.viewControllers objectAtIndex:1];
InfoViewController *infoController = [tabViewController.viewControllers objectAtIndex:2];
MapsViewController *mapController = [tabViewController.viewControllers objectAtIndex:3];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:infoController];
UINavigationController *savingsNav = [[UINavigationController alloc] initWithRootViewController:savingsController];
UITabBarItem *tabBarItem1 = [[tabViewController.tabBar items] objectAtIndex:0];
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:#"tabbar-prices-selected"] withFinishedUnselectedImage:[UIImage imageNamed:#"tabbar-prices-normal"]];
UITabBarItem *tabBarItem2 = [[tabViewController.tabBar items] objectAtIndex:1];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:#"tabbar-savings-selected"] withFinishedUnselectedImage:[UIImage imageNamed:#"tabbar-savings-normal"]];
UITabBarItem *tabBarItem3 = [[tabViewController.tabBar items] objectAtIndex:2];
[tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:#"tabbar-info-selected"] withFinishedUnselectedImage:[UIImage imageNamed:#"tabbar-info-normal"]];
UITabBarItem *tabBarItem4 = [[tabViewController.tabBar items] objectAtIndex:3];
[tabBarItem4 setFinishedSelectedImage:[UIImage imageNamed:#"tabbar-map-selected"] withFinishedUnselectedImage:[UIImage imageNamed:#"tabbar-map-normal"]];
[tabViewController setViewControllers:[NSArray arrayWithObjects:pricesController, savingsNav, navController, mapController, nil]];
[self.navigationController pushViewController:tabViewController animated:YES];
}
GRxTabBarViewController is a UITabBarController and has this in the implementation file.
GRxTabBarViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *backButton = [[UIButton alloc] init];
[backButton setImage:[UIImage imageNamed:#"back"] forState:UIControlStateNormal];
[backButton addTarget:self action:#selector(dismissTab) forControlEvents:UIControlEventTouchUpInside];
backButton.frame = CGRectMake(0, 0, 20.0f, 44.0f);
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = backBarButtonItem;
self.navigationItem.hidesBackButton = YES;
}
-(void)dismissTab
{
[self.navigationController popViewControllerAnimated:YES];
}
Am I doing anything wrong? Am I setting up my tab bar incorrectly? Has someone pushed a tab bar before and have any ideas what I am doing wrong that can help me out? Any guidance or help is appreciated. Thanks in advance!
I'm working on a tabbed application for iOS. Because the tabbar icons are loaded in each viewcontroller separately, I was wondering if it is possible to load all the viewcontrollers at once in the background so all the tabbar icons are loaded when the application is launched.
The tabbar makes use of two icons for each tabbar item (selected and unselected), thats why I choose to load the icons in each viewcontroller separately
And otherwise, is there a possibility to load the tabbar icons in the App delegate?
Yes it is possible. You can initialize all controllers and all images in App delegate's didFinishLaunchingWithOptions methods. Here is the example:
UIViewController *locateTabController = [[LocationTabController alloc] initWithNibName:#"LocationTabController" bundle:nil];
UINavigationController *locationTabNavigationController = [[UINavigationController alloc] initWithRootViewController:locateTabController];
// Product Tab
UIViewController *productsTabController = [[ProductsTabController alloc] initWithNibName:#"ProductsTabController" bundle:nil];
UINavigationController *productsTabNavigationController = [[UINavigationController alloc] initWithRootViewController:productsTabController];
// Delivery Tab
UIViewController *nextDeliveryTabController = [[DeliveryTabController alloc] initWithNibName:#"DeliveryTabController" bundle:nil];
UINavigationController *nextDeliveryTabNavigationController = [[UINavigationController alloc] initWithRootViewController:nextDeliveryTabController];
// Order Tab
UIViewController *standingOrderTabController = [[OrderTabController alloc] initWithNibName:#"OrderTabController" bundle:nil];
UINavigationController *standingOrderTabNavigationController = [[UINavigationController alloc] initWithRootViewController:standingOrderTabController];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:locationTabNavigationController, productsTabNavigationController,nextDeliveryTabNavigationController, standingOrderTabNavigationController, nil];
Here navigation controller is provided as every tab controller class had its own navigation.
You can add titles and images at the same time.
/// Adding titles on each of the tab bar controllers
[[self.tabBarController.viewControllers objectAtIndex:0] setTitle:#"Locate"];
[[[self.tabBarController.viewControllers objectAtIndex:0] tabBarItem]setFinishedSelectedImage:[UIImage imageNamed:#"LocateIconActive.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"LocateIconInactive.png"]];
[[self.tabBarController.viewControllers objectAtIndex:1] setTitle:#"Products"];
[[[self.tabBarController.viewControllers objectAtIndex:1] tabBarItem]setFinishedSelectedImage:[UIImage imageNamed:#"ProductsIconActive.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"ProductsIconInactive.png"]];
[[self.tabBarController.viewControllers objectAtIndex:2] setTitle:#"Delivery"];
[[[self.tabBarController.viewControllers objectAtIndex:2] tabBarItem]setFinishedSelectedImage:[UIImage imageNamed:#"NextDeliveryIconActive.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"NextDeliveryIconInactive.png"]];
[[self.tabBarController.viewControllers objectAtIndex:3] setTitle:#"Order"];
[[[self.tabBarController.viewControllers objectAtIndex:3] tabBarItem]setFinishedSelectedImage:[UIImage imageNamed:#"StandingOrderIconActive.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"StandingOrderIconInactive.png"]];
Sub class your UITabBarController and set the images on the viewWillAppear. I found that this is the cleanest way of doing it.
You dont need to load any viewcontroller when application opens for this purpose. All you have to do is set tabbar icon inside each viewcontroller's initialization method like below:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.tabBarItem.image = [UIImage imageNamed:IMAGE_NAME];
[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:IMAGE_NAME] withFinishedUnselectedImage:[UIImage imageNamed:IMAGE_NAME]];
self.tabBarItem.title = TITLE;
}
return self;
}
After that when you initialize the viewcontroller object from the AppDelegate, tabbar icon will be set.
viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];