0

我有四个不同的单元格,我试图向其中添加图像,每次更改图像时,它都会将图像添加到每个单元格中。我正在尝试为每个单元格添加单独的图像,但我不知道该怎么做。任何帮助都会很棒!这是我的代码:

if ([singletonObj.tempChangelistColor isEqualToString:@"red"]) {

            self.layer.contents = (id)[UIImage imageNamed:@"red.png"].CGImage;

        }else if([singletonObj.tempChangelistColor isEqualToString:@"yellow"]){

          self.layer.contents = (id)[UIImage imageNamed:@"yellow.png"].CGImage;

        }else if([singletonObj.tempChangelistColor isEqualToString:@"green"]){

            self.layer.contents = (id)[UIImage imageNamed:@"green.png"].CGImage;
        }else{

            self.layer.contents = (id)[UIImage imageNamed:@"shop_deal.png"].CGImage;

        }

它位于shop_deal.png的代码底部。

4

2 回答 2

0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"CellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if(cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    if (indexPath.row == 0) {
        cell.imageView.image = [self getImageForCell];
    }
    else if (indexPath.row == 1) {
        cell.imageView.image = [self getImageForCell];
    }
    else if (indexPath.row == 2) {
        cell.imageView.image = [self getImageForCell];
    }
    else (indexPath.row == 3) {
        cell.imageView.image = [self getImageForCell];
    }
    return cell;
}
- (UIImage *)getImageForCell{

    UIImage *returnImage;

    if ([singletonObj.tempChangelistColor isEqualToString:@"red"]) {
        returnImage = [UIImage imageNamed:@"red.png"];
    }
    else if ([singletonObj.tempChangelistColor isEqualToString:@"yellow"]){
        returnImage = [UIImage imageNamed:@"yellow.png"];
    }
    else if([singletonObj.tempChangelistColor isEqualToString:@"green"]){
        returnImage = [UIImage imageNamed:@"green.png"];
    }
    else{
        returnImage = [UIImage imageNamed:@"shop_deal.png"];
    }
    return returnImage;
}
于 2013-09-06T03:44:11.470 回答
0

如果您确切知道手机号码。您想要更改图像,那么这将对您有所帮助。

NSIndexPath *cellIndex = [NSIndexPath indexPathForRow:3 inSection:0]; // suppose cell no is 3 in section 0
UITableViewCell *cell = [_youtTableView cellForRowAtIndexPath:cellIndex];

cell.imageView.image = [UIImage imageNamed:@"shop_deal.png"];

希望这可以帮助。

于 2013-09-06T04:20:55.537 回答