代码之家  ›  专栏  ›  技术社区  ›  Atma

表视图中的所有图像在iPhone应用程序中都是相同的

  •  0
  • Atma  · 技术社区  · 14 年前

    我有一个表格视图,在那里我希望每个单元格基于逻辑有一个不同的图像。这是我的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;
    }
    

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

    1 回复  |  直到 14 年前
        1
  •  1
  •   Tejaswi Yerukalapudi    14 年前

    它可能是比较代码,用来比较 imageForInventory 使用 [str1 isEqualToString:str2] = 现在是赋值运算符,但是即使你把它改成 == 那是行不通的。