我的UITableView
滞后因为我已经包含了一张图片 -
cell.imageView.image = [[UIImage alloc] initWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:[NSString stringWithFormat:@"image.png"]]];
代码有问题吗?
答案 0 :(得分:0)
图像的分配可能是您的问题。您可能不应该在您的cellForRowAtIndexPath中执行此操作,因为这是一项昂贵的操作。 根据您的使用情况,尝试分配和缓存之前的图像
答案 1 :(得分:0)
您还可以使用内置内部缓存的[UIImage imageNamed:]
。如果您多次重复使用相同的图像,这将非常有用。
答案 2 :(得分:0)
使用该方法导致内存泄漏。你在alloc
上打电话给UIImage
而我认为你没有发布它(我没有你的代码,所以我不知道)。你应该使用
[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:
[NSString stringWithFormat:@"image.png"]]];
或者更简单地说,只需使用
即可[UIImage imageNamed:@"image.png"];