开发者

iOS: UITabBarController - lazy loading of item views

开发者 https://www.devze.com 2023-03-11 21:43 出处:网络
I have read that subclassing a UITabBarController is a non-recommended practice. However, how then is possible to implement lazy loading of the views of tab bar items?

I have read that subclassing a UITabBarController is a non-recommended practice. However, how then is possible to implement lazy loading of the views of tab bar items?

I'm playing around with a standard app view hierarchy: In my main app delegate file (application:didFinishLaunchingWithOptions:) , I'm instantiating a custom subclass of UITabBarController with a 4 tab bar items / icons. I only need to load the first view of the first tab bar item - other views should be loaded lazily upon request. So, in application:didFinishLaunchingWithOptions:, I'm loading welcome view and pus开发者_运维技巧hing it into the first UINavigationController(1). The other tab bar items are empty UINavigationControllers - (2, 3, 4). Here is my custom subclass of UITabBarController that is also a delete of himself:

@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 view of the second tab bar item is just a UIViewController but I it will become a UINavigationController soon :)

So, back to the problem, what other (more apple-complaint) options would be to implement tab bar item action handling for lazy-loading?


If I understand your question correctly, by default TabbarController loads item's view in lazy mode. That is, unless you click on a certain item on tab bar, it won't be loaded.

You can check this by putting log on each view's viewdidload and see when it is getting called.

0

精彩评论

暂无评论...
验证码 换一张
取 消