0

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

- (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;

}

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

4

4 回答 4

1

您的延迟可能是因为您正在从主线程上 cellForRowAtIndexpath 中的磁盘加载。尽量避免在主线程上进行 I/O 操作。看看这里:使用块从后台线程加载图像

于 2012-11-01T09:16:47.073 回答
0

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

于 2012-11-01T07:41:33.120 回答
0

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

于 2012-11-01T07:43:11.650 回答
0

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

你可以阅读:

UIImage 的 imageNamed 是否仍然会在 iOS4 上导致大图像出现内存问题?

于 2012-11-01T07:52:16.673 回答