Search code examples
iphoneuitabbaruitabbaritem

uitabbar and uitabbaritem


I am trying to add UITabBarItems to a UITabBar not to a tabbar controller. Here is what I tried to do. It is always crashing when I am calling setItems. Can any please point out whats wrong.

My_Accounts *my_AccountsVC = [[My_Accounts alloc] init];
Payments *paymentsVC = [[Payments alloc] init];
Transfer *transferVC = [[Transfer alloc] init];
NSArray *VCArray = [[NSArray alloc] initWithObjects:my_AccountsVC,paymentsVC,transferVC, nil];
[self.tabbar setItems:VCArray];

Thanks


Solution

  • If you look at items, it takes an array of UITabBarItems and not UIViewController subclasses which you seem to be passing.

    You will have to keep track of the view controllers elsewhere and pass an array of UITabBarItems and handle the view controllers in the UITabBar's delegate.

    Or much better, use UITabBarController.