Добавить несколько изображений в ячейках в UITableView - PullRequest
0 голосов
/ 10 декабря 2011

Как добавить несколько изображений в одну ячейку в UITableView?

Я хочу использовать изображения для обозначения статуса игрока, и у каждого игрока может быть несколько статусов одновременно.

1 Ответ

6 голосов
/ 10 декабря 2011

наследуют UITableViewCell, чтобы создать собственную ячейку.Допустим, он называется MyCustomCell.

, используйте его, как показано ниже

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

    // In your case it has to be the custom cell object here.

    MyCustomCell *cell = (MyCustomCell*)[tableView dequeueReusableCellWithIdentifier:@"AnIdentifierString"];

    if (cell == nil) 
    {
        cell = [[[MyCustomCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"AnIdentifierString"] autorelease];
    }

    //use your cell here
    //  cell.textLabel.text = @"This text will appear in the cell";
    return cell;
}

Вы можете переопределить init со стилем MyCustomCell следующим образом для нескольких изображений

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

    //change frame sizes to palce the image in the cell
        UIImageView * thumbnail1 = [[UIImageView alloc] initWithFrame:CGRectMake(17, 12, 62, 62)];
        thumbnail1.image = [UIImage imageNamed:@"Icon.png"];
        [self addSubview:thumbnail1];

        UIImageView * thumbnail2 = [[UIImageView alloc] initWithFrame:CGRectMake(17, 12, 62, 62)];
        thumbnail2.image = [UIImage imageNamed:@"Icon.png"];
        [self addSubview:thumbnail2];

        UIImageView * thumbnail3 = [[UIImageView alloc] initWithFrame:CGRectMake(17, 12, 62, 62)];
        thumbnail3.image = [UIImage imageNamed:@"Icon.png"];
        [self addSubview:thumbnail3];

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