表查看加载性能问题

时间:2012-09-30 19:13:29

标签: performance uitableview

我有一个UITableView,有七行,每行包含文本和.png图像。当我添加代码来为每行设置图像并在模拟器中运行应用程序时,我会遇到很长的加载时间。

我怀疑性能问题的原因是我的图像尺寸太大而且我正在将图像缩放到适当的像素尺寸。但是,我想确保在代码中没有什么可以做的不同以进一步优化性能。我的代码中有什么不同的做法吗?

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *c = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

    if (!c)
    {
        c = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                   reuseIdentifier:@"Cell"];
    }
//adds text to table view
    [[c textLabel] setText:[categoryNames objectAtIndex:[indexPath row]]];
    [[c textLabel] setTextColor:[UIColor whiteColor]];

    //add pictures to table view

    NSString *path = [[NSBundle mainBundle] pathForResource:[categoryURLs objectAtIndex:[indexPath row]] ofType:@"png"];
    [[c imageView] setImage:[UIImage imageWithContentsOfFile:path]];

    return c;


}

1 个答案:

答案 0 :(得分:0)

通过将图像调整为44x44像素(标准UITableViewCell高度)和88x88(@ 2x视网膜图像)来解决问题。