IOS: UITabBarController - lazy loading element views

I read that subclassing UITabBarController is not a recommended practice. However, how then can you implement lazy loading of tab bar item views?

I play with the standard hierarchy of application representations. In my main application delegate doing (application: didFinishLaunchingWithOptions :) I am creating my own subclass of UITabBarController with elements / icons in 4 tabs. I only need to load the first view of the first element of the tab bar - other views should be loaded lazily upon request. So, in the application: didFinishLaunchingWithOptions :, I load the welcome view and paste it into the first UINavigationController (1). Other tab bar items are empty UINavigationControllers - (2, 3, 4). Here is my custom subclass of UITabBarController, which is also deleting itself:

@interface MainUITabBarController : UITabBarController <UITabBarControllerDelegate> { } @end @implementation MainUITabBarController -(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{ UIImageView *image = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TableViewBG.jpg"]] autorelease]; UIViewController *vc = [self.viewControllers objectAtIndex:item.tag]; vc.view = image; } @end 

Currently, the presentation of the second element of the tab bar is only a UIViewController, but I will soon become a UINavigationController :)

So, back to this problem, what other (more appetizing) options will be implemented to handle the actions of the tab bar item for lazy loading?

+4
source share
1 answer

If I understand your question correctly, by default, TabbarController loads the item view in lazy mode. That is, if you do not click on a specific item in the tab bar, it will not be loaded.

You can verify this by putting a log in each viewdidload view and see when it is called.

+4
source

All Articles