Как разместить 3 изображения в 1 ячейке - PullRequest
0 голосов
/ 09 марта 2012

Я реализовал LazyTableImage в моем примере проекта.Я хочу показать 3 изображения в моей 1 ячейке, можете ли вы сказать мне, как я могу это сделать, вот мой пример кода, который приведен ниже, я могу попытаться сделать это, но не показано 3 изображения в 1 ячейке, могу ли я сделать алгоритмкоторый отлично работает в других проектах, но 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;
}

Ответы [ 2 ]

1 голос
/ 10 марта 2012

У вас есть только 1 imageView в cell.Вы должны создать пользовательский UITableViewCell, как предложено @alan duncan.

в вашем коде вы можете получить вот так:

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 голос
/ 10 марта 2012

Я бы разработал пользовательский UITableViewCell в своем собственном перо;так что вы можете визуально расположить три UIImageView экземпляра.

Тогда вместо [[UITableViewCell alloc] init...] вы загрузите ячейку из кончика, либо напрямую, либо создайте его экземпляр с помощью UINib.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...