你知不知道这些图像不可能一下子被记住?如果你想在它们之间滚动,你必须把它们页进页出,以保持一个像样的内存占用。
至于加载它们,您可能应该显示一个微调器,开始在后台加载图像,然后在图像准备好后将其替换为图像。使用加载图像
NSURLConnection
是过度杀戮,你可能会更容易
imageNamed:
- (void) startLoadingImage {
// You need an autorelease pool since you are running
// in a different thread now.
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
UIImage *image = [UIImage imageNamed:@"foo"];
// All GUI updates have to be done from the main thread.
// We wait for the call to finish so that the pool wonât
// claim the image before imageDidFinishLoading: finishes.
[self performSelectorOnMainThread:@selector(imageDidFinishLoading:)
withObject:image waitUntilDone:YES];
[pool drain];
}
- (void) viewDidLoad {
UIActivityIndicator *spinner = â¦;
[self.view addSubview:spinner];
[self performSelectorInBackground:@selector(startLoadingImage)
withObject:nil];
}
- (void) imageDidFinishLoading: (UIImage*) image {
// fade spinner out
// create UIImageView and fade in
}
方法名是从内存中拼写的,我可能遗漏了一个参数。但原则上,这个密码是正确的。