2012-03-09 96 views
0

我在我的示例项目中实施了LazyTableImage。我想在我的1个单元格中显示3个图像,你能告诉我我该怎么做,这里是我的示例代码,下面给出我可以尝试做到这一点,但它没有显示3个图像在1个单元格中,我可以使算法它工作在其他项目很好,但LazyTableImage它不工作,请告诉我,我怎么能做到这一点...如何在1个单元格中放置3个图像

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 
    static NSString *PlaceholderCellIdentifier = @"PlaceholderCell"; 

    int nodeCount = [self.currentSelectedCategoryArray count]/4; 

    if (nodeCount == 0 && indexPath.row == 0) 
    { 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PlaceholderCellIdentifier]; 
     if (cell == nil) 
     { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
              reuseIdentifier:PlaceholderCellIdentifier] autorelease]; 
      cell.detailTextLabel.textAlignment = UITextAlignmentCenter; 
      cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     } 

     cell.detailTextLabel.text = @"Loading…"; 

     return cell; 
    } 

    UITableViewCell *cell = [self.detailCatTable dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
             reuseIdentifier:CellIdentifier] autorelease]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 

    int check = indexPath.row; 
    check = check*3; 

     for (int i = 0; i < 3; i++){ 

      if(check+i < [self.currentSelectedCategoryArray count]){ 

       if (nodeCount > 0) 
       { 
        // Set up the cell... 
        imageClass *imgC = [self.currentSelectedCategoryArray objectAtIndex:check+i]; 

        cell.textLabel.text = imgC.imageName; 
        cell.detailTextLabel.text = imgC.imageID; 

        // Only load cached images; defer new downloads until scrolling ends 
        if (!imgC.cImage) 
        { 
         if (tableView.dragging == NO && tableView.decelerating == NO) 
         { 
          [self startImageDownload:imgC forIndexPath:indexPath]; 
         } 
         // if a download is deferred or in progress, return a placeholder image 
         cell.imageView.image = [UIImage imageNamed:@"imageFrame.png"];     
        } 
        else 
        { 
         cell.imageView.image = imgC.cImage; 
        } 

       } 

      } 

     } 
return cell; 
} 

回答

1

您只有1 imageViewcell。您应该按照建议的@alan duncan创建自定义UITableViewCell

在你的代码

你可以有这样的:

switch(i){ 
    case 0: 
     ((UIImageView*)[cell.contentView viewWithTag:1]).image = imgC.cImage; 
    break; 

    case 1: 
     ((UIImageView*)[cell.contentView viewWithTag:2]).image = imgC.cImage; 
    break; 

    case 2: 
     ((UIImageView*)[cell.contentView viewWithTag:3]).image = imgC.cImage; 
    break; 
} 

我希望你的想法。

1

我会设计一个自定义UITableViewCell在自己的笔尖;以便您可以直观地布置三个UIImageView实例。

然后而不是[[UITableViewCell alloc] init...]您将从笔尖加载单元,直接或通过UINib实例化。

相关问题