2012-03-09 108 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實例化。

相關問題