【问题标题】:Tableview scrolling is not so smooth?Tableview滚动不是那么流畅?
【发布时间】:2012-11-01 07:28:31
【问题描述】:

我有一个包含三个不同自定义单元格的表格视图。每个单元格将从三个不同的单元格类加载。`

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier1 = @"CellIdentifier";
    static NSString *CellIdentifier2 = @"Cell";
     static NSString *CellIdentifier3 = @"Cell";
    if (indexPath.section == 0)
    { 
         CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];

        if (cell == nil)
        {
            cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier1] autorelease];
        }
        cell.datelabel.text=@"dhhg";
      cell.nameLabel.text=@"shdhsjdj";
    cell.msg.text=@"sdhhhfhjhfj";

       cell.myImageView.image=[UIImage imageNamed:@"sd.png"]; 
        cell.likelabel.text=@"hhhf";

        return cell;

    }
    else 
    {


        Customcellwithimage *cell = (Customcellwithimage *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];

        if (cell == nil)
        {
            cell = [[[Customcellwithimage alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier2] autorelease];
        }
        cell.datelabel1.text=@"sdhkhks";
        cell.nameLabel1.text=@"sdhjkhkshd";
        cell.msg1.text=@"sdsdsd";

        cell.myImageView1.image=[UIImage imageNamed:@"shdjhjhs"]; 
        cell.likelabel1.text=@"sjdh";
        cell.bannerview1.image=[UIImage imageNamed:@"dshjs"]; 

        return cell;
    }

 return Nil;

}

` .这是我的设计代码。谁能帮我解决我哪里出错了?

【问题讨论】:

  • 当您取消注释图像内容时会发生这种情况吗?
  • 它是从我的自定义类加载的。单元格本身包含一个图像。
  • 是的,所以当你取消注释所有处理图像的代码时检查它是否仍然滞后,以便最终没有图像被加载。基本上,这应该可行,并且您有证据证明您的图像会导致滞后。
  • 你使用网络图片对吗?

标签: iphone ios ipad


【解决方案1】:

您的延迟可能是因为您正在从主线程的 cellForRowAtIndexpath 中的磁盘加载。尽量避免在主线程上进行 I/O 操作。看看这里:loading images from a background thread using blocks

【讨论】:

    【解决方案2】:

    检查您的图片尺寸。 如果图像尺寸较大,表格视图将不平滑

    【讨论】:

    • 你应该准备你的图像以适合你的图像视图大小。在添加到您的项目之前。前任。正常显示为 50x50,视网膜显示为 100x100
    【解决方案3】:

    首先 cellIdentifier2 和 cellIdentifier3 与@"cell" 具有相同的值。
    您只包含了 2 个条件,一个用于第零节,第二个用于其他条件。
    您还应该提及使用 cellIdentifier3 的条件。
    您没有提到您遇到的问题,因为您的代码似乎没有任何错误。
    你想要什么输出?不同部分的不同单元格??

    【讨论】:

    • 不。我想为我从 webservise 获得的不同类型的响应加载不同的单元格。作为经验,我已经这样做了。
    • 可能存在加载具有较大分辨率的图像的问题,这在表格视图单元格中可能不需要。因此,您可以在服务器或项目中使用较小的图像。但如果您不知道收到的图片大小,可以尝试调整图片大小。
    【解决方案4】:

    您的代码对我来说似乎非常好。避免使用[UIImage imageNamed:@"sd.png"],因为它曾经在 ios 3.0 之前造成内存问题,但是对于大图像,它仍然可能会造成问题。

    您可以阅读:

    Does UIImage's imageNamed still cause memory issues on iOS4 for large images?

    【讨论】:

      猜你喜欢
      • 2020-01-02
      • 2014-12-06
      • 2018-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多