UIImage不在表视图中显示

时间:2012-07-25 14:22:32

标签: ios xcode uitableview uiimage

我试图在每一行显示图像。我有一个开关来决定哪张图片。我没有显示任何图片。有人遇到同样的问题吗?

以下是代码:

    self.statIcon = (UIImage *)[cell viewWithTag:42];

    NSString *statusPath;
    switch ([[[self.logList objectAtIndex:position] objectForKey:@"STATE"] intValue]) {
        case 1:
            statusPath = [[NSBundle mainBundle] pathForResource:@"log_acc" ofType:@"png"];
            break;
        case 2:
            statusPath = [[NSBundle mainBundle] pathForResource:@"log_dec" ofType:@"png"];
            break;
        case 3:
            statusPath = [[NSBundle mainBundle] pathForResource:@"log_rights" ofType:@"png"];
            break;
        default:
            statusPath = [[NSBundle mainBundle] pathForResource:@"log_rights" ofType:@"png"];
            break;
    }
    UIImage *statImg = [[UIImage alloc] initWithContentsOfFile:statusPath];
    self.statIcon = statImg;

来自DEBUGGER:

(NSString *) $1 = 0x001218b0 /var/mobile/Applications/167CC386-A0EE-4E05-BADD-B0307A01D684/My App.app/log_acc.png

(UIImage *) $0 = 0x00132e20 <UIImage: 0x132e20>

1 个答案:

答案 0 :(得分:1)

好的,感谢David H我能够找到问题的解决方案。主要问题是,self.statIconUIImage而不是UIImageView。所以只需改变类型,最后使用函数setImage

以下是代码:

    self.statIcon = (UIImageView *)[cell viewWithTag:42];
    NSString *statusPath;
    switch ([[[self.logList objectAtIndex:position] objectForKey:@"STATE"] intValue]) {
        case 1:
            statusPath = [[NSBundle mainBundle] pathForResource:@"log_acc" ofType:@"png"];
            break;
        case 2:
            statusPath = [[NSBundle mainBundle] pathForResource:@"log_dec" ofType:@"png"];
            break;
        case 3:
            statusPath = [[NSBundle mainBundle] pathForResource:@"log_rights" ofType:@"png"];
            break;
        default:
            statusPath = [[NSBundle mainBundle] pathForResource:@"log_rights" ofType:@"png"];
            break;
    }
    UIImage *statImg = [UIImage imageWithContentsOfFile:statusPath];
    [self.statIcon setImage:statImg];