开发者

UITableView - Load large UIImages from NSBundle without blocking main thread

In UITableViewController, the UI freezes when this method is called: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

where an image is being loaded into the UITableViewCell.

cell.imageView.image = [UIImage imageWithContentsOfFile:@"filePath"];

The files are locally stored in the documents folder - this is not a remote call. I understand that image-loading while the cell is created cusses the main开发者_运维知识库 thread to freeze, if this was a remote call i would have uses a-synchronic loading but how would you do it for local files?

*images are around 500k.

Need help. Thanks.


For example, make separate thread where you will load images and save reference to them in some array. When all images will be prepared (or some part of them), you can reload cells that should contains that messages.

In table view controller you should check if image is already loaded for that cell and if it is just take reference and set cell.imageView.image with it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜