1

I'm using this method http://redartisan.com/2010/6/27/uisegmented-control-view-switching-revisited to create a custom UITabBar and loading a particular view when a certain TabBarItem is clicked.

The problem is that initially the first view is loaded, but the first tab bar item is not highlighted. Is there a way to force the highlight? I'm not using the tabbarcontroller so I can't use its methods.

James
  • 1,689
  • 3
  • 17
  • 21

1 Answers1

2

If you make an instance variable: UITabBar *tabBar; a property:

@property (nonatomic, assign) IBOutlet UITabBar *tabBar;

and connect this property to the UITabBar in Interface Builder, you can use:

for(UITabBarItem *tab in tabBar.items) {
    if ([tab.title isEqualToString: @"My Tab Title"]) {
        tabBar.selectedItem = tab;
        }
    }

This works if all tabs have a unique title, which is normally the case.

Jan Kroon
  • 89
  • 6