objective-c - 如何在 1 个单元格中放置 3 个图像

标签 objective-c ios cocoa-touch uitableview

我已经实现了 LazyTableImage在我的示例项目中。我想在我的 1 个单元格中显示 3 个图像,你能告诉我我该怎么做吗?这是我的示例代码,下面给出我可以尝试这样做,但它没有在 1 个单元格中显示 3 个图像,我可以制作算法吗这在其他项目中工作正常但 LazyTableImage 它不工作请告诉我我该怎么做...

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

最佳答案

cell 中只有 1 个 imageView。您应该按照@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;
}

我希望你明白这一点。

关于objective-c - 如何在 1 个单元格中放置 3 个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9639834/

相关文章:

ios - 未安装应用程序时,Firebase Dynamic链接打开Weblink而不是App Store

objective-c - 我们如何实现selectionRectsForRange : from UITextInput Protocol?

objective-c - plist 文件加载的 NSDictionary 内存泄漏

iphone - 缩放时带有 UIImageView 的 UIScrollView 居中旋转?

ios - Collection View 完成处理程序的 PerformBatchUpdates 未执行

ios - 带有 UIView 的自动布局标签和 UIView 内的标签

objective-c - 在基于 View 的表中获取按钮的行

objective-c - iOS 似乎绕过了基本的服务器身份验证

ios - 导入 Obj-C 文件,该文件导入自动生成的 Swift header

cocoa - iPad 方向问题