小编Cyr*_*roy的帖子

为什么iOS main.m模板包含return语句和自动释放池?

我正在重新阅读UIApplicationMain文档,并想知道,如果UIApplicationMain永远不会返回,为什么:

  • 有没有return在结束了吗?
  • NSAutoreleasePool吗?

我甚至问自己:为什么int main(int argc, char *argv[])在iPhone上?我们可以使用命令行启动应用程序吗?什么是argcargv为什么?它们是使用还是只是遗留C?

来自尊贵的研究员的推特上的一些评论是:

  • return 在这里为编译器
  • NSAutoreleasePool是没用的.
  • 运行循环需要分配一个自动释放池(与#2相矛盾)

cocoa-touch objective-c ios

9
推荐指数
1
解决办法
965
查看次数

强制iOS上的图像加载预加载

我想预先加载图像,当我将他们的UIImageView添加到我的currentView时,PNG已经在内存中,加载,充气等.

从这次时间分析中可以看出,图像在显示时会被加载: 在此输入图像描述

与此同时,我之前已经预先加载了这些图像.就在我加载该视图时,我使用该代码彻底创建了这些动画的所有图像和图像视图:

- (UIImageView*)createAnimationForReel:(NSString*)reel ofType:(NSString*)type usingFrames:(NSInteger)frames{
    UIImageView *imageView = [[UIImageView alloc] init];
    NSMutableArray *imageArray = [NSMutableArray arrayWithCapacity:frames];

    for (int i=0;i<frames;i++){
        NSString *image;
        if(i<10){
            image = [NSString stringWithFormat:@"%@_0%i", reel, i];
        } else {
            image = [NSString stringWithFormat:@"%@_%i", reel, i];
        }
        NSString *path = [[NSBundle mainBundle] pathForResource:image ofType:@"png" inDirectory:type];
        UIImage *anImage = [[UIImage alloc] initWithContentsOfFile:path];
        [imageArray addObject:anImage];
    }
    imageView.animationImages = [NSArray arrayWithArray:imageArray];
    imageView.animationDuration = 2.0;
    return imageView;
}
Run Code Online (Sandbox Code Playgroud)

当我阅读文档时,它说:"此方法将图像数据加载到内存中并将其标记为可清除.如果数据被清除并需要重新加载,则图像对象将从指定路径再次加载该数据." 谈论initWithContentOfFile.所以我的图像"应该"被加载.

但不是.

当然,我的反思中缺少一些东西.但是什么?

image preload ios

6
推荐指数
2
解决办法
4436
查看次数

标签 统计

ios ×2

cocoa-touch ×1

image ×1

objective-c ×1

preload ×1