4

When I use the this method to initialize a UITabBarItem:

- (id)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag

Do I need to have a distinct tag for each tab bar item, or (since I don't use them) can I simply use the same tag value for all of them?

Sophie Alpert
  • 139,698
  • 36
  • 220
  • 238

2 Answers2

6

I'm pretty sure you can just leave them all as 0 or any other number you choose. Every UIView can potentially have a different tag, and Interface Builder sets them all to 0 by default. I haven't run into any problems with this.

pix0r
  • 31,139
  • 18
  • 86
  • 102
  • Thanks, I'll trust you on that. ; ) – Sophie Alpert Jun 19 '09 at 22:06
  • 1
    My iPhone app had all of them 0 for a long time and it was fine. Now i'm going to set them to values just so I can do 'if' or 'switch' statements to easily identify which element is sending events etc. – Jonathan Oct 19 '13 at 23:35
2

From Apple's UITabBarItem class reference:

tag - The receiver’s tag, an integer that you can use to identify bar item objects in your application.

So it looks like it doesn't really matter.

Tobias Svensson
  • 149
  • 1
  • 5