C
--
Questions
--
Followers
Top Experts
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Just create a new vUITabBarItem object and replace the object you don't want to hang around in the tabbar.
Set the new item array using the UITabBar.items property.
There is no way to disable an item. You can create another view and put that on top of the view you want disabled though. Make sure it does not propagate it's touch events to the view below it. (Not sure if it will by default anyway)






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
// create a new UITabBarItem, you decide what value you want to use for tagForNewItem
UITabBarItem *newItem = [[UITabBarItem alloc] initWithTitle:@"Title" image:someImageObject tag:tagForNewItem];
// create a mutable array with the tab bar items
NSMutableArray *barItems = [NSMutableArray arrayWithArray:self.tabBar
// replace item, you must figure out the index of the object,
// typically you would use item.tag when you replace the item when it is clicked but
// otherwise you'll have to find a way to identify it's position in the array to be able to replace it.
[barItems replaceObjectAtIndex:item.
// set the new item list
self.tabBar.items = barItems;
// don't leak
[newItem release];
Then in -(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarIte
you need to check the tag of the newly created item to decide what to do when the item is clicked.
Example:
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarIte
{
      switch(item.tag)
      {
           case tagForNewItem:
                 // perform your view change code here
           break;
           .......
      }
}
Is this what you wanted?

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
let me explain
i want the user to be able to click the first tab bar item, then click a button inside that view that sends them to another view that's on the tab bar. Â when the user tries to click the first tab bar item again, it should change the view to a different first view.
i think you got it so i'm guessing the method that you sent me changes the view to what i want inside the case switch function
still a beginner. sorry.
do i have to declare tabBar as something like UITabBarItem. Â it keeps throwing an error






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
in the AppDelegate.m or on the view?
UITabBar *tabBar = ....;
tabBar.delegate = self;
Make sure you implement the protocol in your .h file:
@interface ViewControllerName <UITabBarDelegate>
Then put the didSelectItem: method in the .m file

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
#import <UIKit/UIKit.h>
@interface TabTestAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate
  UIWindow *window;
  UITabBarController *tabBarController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end
AppDelegate.m
#import "TabTestAppDelegate.h"
@implementation TabTestAppDelegate
@synthesize window;
@synthesize tabBarController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIAppli
 Â
  // Override point for customization after application launch.
  // Add the tab bar controller's view to the window and display.
  [window addSubview:tabBarControlle
  [window makeKeyAndVisible];
  return YES;
}
- (void)applicationWillResig
  /*
   Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
   Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
   */
}
- (void)applicationDidEnterB
  /*
   Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
   If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
   */
}
- (void)applicationWillEnter
  /*
   Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
   */
}
- (void)applicationDidBecome
  /*
   Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
   */
}
- (void)applicationWillTermi
  /*
   Called when the application is about to terminate.
   See also applicationDidEnterBackgro
   */
}
#pragma mark -
#pragma mark UITabBarControllerDelegate
/*
// Optional UITabBarControllerDelegate
- (void)tabBarController:(UI
}
*/
/*
// Optional UITabBarControllerDelegate
- (void)tabBarController:(UI
}
*/
#pragma mark -
#pragma mark Memory management
- (void)applicationDidReceiv
  /*
   Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
   */
}
- (void)dealloc {
  [tabBarController release];
  [window release];
  [super dealloc];
}
@end
FirstViewController.h
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController {
      UIButton *dis;
}
@property (nonatomic, retain) IBOutlet UIButton *dis;
-(IBAction) display:(id) sender;
@end
FirstViewController.m
@implementation FirstViewController
@synthesize dis;
-(IBAction) display:(id) sender{
      [[[[[self tabBarController] viewControllers] objectAtIndex:0] tabBarItem] setEnabled:false];
}
SecondViewController.h
@interface SecondViewController : UIViewController {
      UIButton *dis2;
}
@property (nonatomic, retain) IBOutlet UIButton *dis2;
-(IBAction) diss:(id) sender;
@end
SecondViewController.m
@implementation SecondViewController
@synthesize dis2;
-(IBAction) diss:(id) sender{
      [[[[[self tabBarController] viewControllers] objectAtIndex:0] tabBarItem] setEnabled:true];
}
This is the effect that i want kind of but instead of disabling the button i want it to show another view like we talked about. Â FirstAViewController
#import <UIKit/UIKit.h>
@interface DisDatTestAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate
  UIWindow *window;
  UITabBarController *tabBarController;
      UITabBar *tabBar;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) IBOutlet UITabBar *tabBar;
@end
AppDelegate.m
#import "DisDatTestAppDelegate.h"
@implementation DisDatTestAppDelegate
@synthesize window;
@synthesize tabBarController;
@synthesize tabBar;
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarIte
{
      switch(item.tag)
      {
           case 0:
                 // first item
                 // display the view you want the first time
                 //YourViewController *ctrl = .........;
                 // addSubview or whatever you use to display it (might be a navigationController, I dont know)
      break;
           case 1:
                 // second item
      break;
           case 2:
                 // third item
                 // let's say this is the one which presents your view with a button,
                 // that when clicked, should replace the first item on the tabbar
                 // in the replace tabbar item code, set the tag of the new item to some far out value, like 9999 or whatever
                 // ie: UITabBarItem *newItem = [[UITabBarItem alloc] initWithTitle:@"Title" image:someImageObject tag:9999];
      break;
           case 9999:
                 // display the different view when the user clicks the first item on the tab bar
                 //DifferentViewForFirstTab
                 // addSubview or whatever you use to display it (might be a navigationController, I dont know)
                 // if you need to replace the first tab bar item again remember to set it's tag to 0 this time.
      break;
     Â
      // .........
      }
}
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIAppli
 Â
  // Override point for customization after application launch.
  // Add the tab bar controller's view to the window and display.
  [window addSubview:tabBarControlle
  [window makeKeyAndVisible];
  return YES;
}
- (void)applicationWillResig
  /*
   Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
   Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
   */
}
- (void)applicationDidEnterB
  /*
   Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
   If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
   */
}
- (void)applicationWillEnter
  /*
   Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
   */
}
- (void)applicationDidBecome
  /*
   Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
   */
}
- (void)applicationWillTermi
  /*
   Called when the application is about to terminate.
   See also applicationDidEnterBackgro
   */
}
#pragma mark -
#pragma mark UITabBarControllerDelegate
/*
// Optional UITabBarControllerDelegate
- (void)tabBarController:(UI
}
*/
/*
// Optional UITabBarControllerDelegate
- (void)tabBarController:(UI
}
*/
#pragma mark -
#pragma mark Memory management
- (void)applicationDidReceiv
  /*
   Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
   */
}
- (void)dealloc {
  [tabBarController release];
  [window release];
  [super dealloc];
}
@end
FirstViewController.h
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController {
      IBOutlet UIButton *dis;
}
@property (nonatomic, retain) UIButton *dis;
-(IBAction) disable:(id)sender;
@end
FirstViewController.m
#import "FirstViewController.h"
#import "DisDatTestAppDelegate.h"
@implementation FirstViewController
@synthesize dis;
-(IBAction) disable:(id)sender {
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test" message:@"Test" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
     Â
      [alert show];
      [alert release];
     Â
      /*UIImage* anImage = [UIImage imageNamed:@""];
      UITabBarItem *newItem = [[UITabBarItem alloc] initWithTitle:@"Title" image:anImage tag:0];
     Â
      NSMutableArray* newArray = [NSMutableArray arrayWithArray:self.tabBar
     Â
      [newArray replaceObjectAtIndex:0 withObject:newItem];
     Â
      [self.tabBarController setViewControllers:newArra
     Â
      UIImage* anImage = [UIImage imageNamed:@""];
      UITabBarItem *newItem = [[UITabBarItem alloc] initWithTitle:@"Title" image:anImage tag:0];
      // create a mutable array with the tab bar items
      NSMutableArray *barItems = [NSMutableArray arrayWithArray:self.tabBar
      // replace item, you must figure out the index of the object,
      // typically you would use item.tag when you replace the item when it is clicked but
      // otherwise you'll have to find a way to identify it's position in the array to be able to replace it.
      [barItems replaceObjectAtIndex:0 withObject:newItem];
      // set the new item list
      //[self.tabBarController setViewControllers:barItem
      // don't leak
      [newItem release];
      [anImage release];
     Â
}
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSStr
  if ((self = [super initWithNibName:nibNameOrN
    // Custom initialization
  }
  return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
  [super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToIn
  // Return YES for supported orientations
  return (interfaceOrientation == UIInterfaceOrientationPort
}
*/
- (void)didReceiveMemoryWarn
      // Releases the view if it doesn't have a superview.
  [super didReceiveMemoryWarning];
     Â
      // Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
      // Release any retained subviews of the main view.
      // e.g. self.myOutlet = nil;
}
- (void)dealloc {
  [super dealloc];
}
@end

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
C
--
Questions
--
Followers
Top Experts
C is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instructions, so it has found lasting use in applications that had formerly been coded in assembly language, including operating systems as well as various application software for computers ranging from supercomputers to embedded systems. It is distinct from C++ (which has its roots in C) and C#, and many later languages have borrowed directly or indirectly from C.