My app is all done and working great. So now I ran it on a old iPhone and the app takes 17.3 seconds to start!?!? i spent a lot of time looking into it and i found that the reason it is taking so long to load is i have a lot of views and each view has a png background image. All my views and made in IB and in my code:
#import "MyTestAppDelegate.h"
#import "MyTestViewController.h"
@implementation MyTestAppDelegate
@synthesize window;
@synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end
At t开发者_运维百科he end of the code where is says:
[window addSubview:viewController.view];
the app seems to be loading all the views in the nib at the same time. All the png's from all the views are about 12mb. There is no need for the app to load all the views at the same time during startup.
Is there a way i can only load the first "home" view at startup? (All the views are part of the same nib.)
You can try splitting your views into different nibs. Using one nib for a single UIViewController
and UIView
seems to be the recommended way.
If you do that, the view will only be loaded when it's first accessed.
When you load a nib, the runtime instantiates all the objects freeze dried in the nib. If you have all your views in a single nib then every single view will initialize and load even if it is not visible. Otherwise the links in the nib couldn't be resolved.
Usually, each nib should be a view/view-controller pair. Multiple view controllers can be placed in the same nib safely because they are usually relatively lightweight objects.
精彩评论