все изображения в табличном представлении одинаковы в приложении iPhone - PullRequest
0 голосов
/ 22 сентября 2010

У меня есть табличное представление, где я хочу различное изображение для каждой ячейки на основе логики.Вот мой код cellforrowatindexpath:

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

    static NSString *MyIdentifier = @"MyIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                       reuseIdentifier:MyIdentifier] autorelease];
    }


    NSInteger *row = [indexPath row];
    NSString *platform = [[myStringArray objectAtIndex: row];
    cell.imageView.image = [self imageForInventory:platform];

    return cell;
}

Вот мой метод imageForInventory:

- (UIImage *)imageForInventory:(NSString *)platform {   
    if (platform = @"Win") {
        UIImage *winImage = [UIImage imageNamed:@"Vista.png"];

        return winImage;
    }else if (platform = @"Mac") {
        UIImage *appleImage = [UIImage imageNamed:@"Apple.png"];
        return appleImage;
    }else if (platform = @"Linux") {
        UIImage *linuxImage = [UIImage imageNamed:@"Linux.png"];
        return linuxImage;
    }   

    return nil;
}

Это показывает winImage для каждой строки, игнорируя операторы if.Как мне получить изображение для соответствующей ячейки?

1 Ответ

1 голос
/ 22 сентября 2010

Вероятно, это ваш код сравнения, для сравнения строк в imageForInventory используйте [str1 isEqualToString:str2].Вы используете =, который сейчас является оператором присваивания, но даже если вы измените его на ==, он не будет работать.

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