表视图显示项目中的图像

时间:2013-03-26 10:19:11

标签: ios tableview

我正在尝试添加我在项目中添加的图像,我使用以下代码

UIView *selectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 7, 320, 50)];
    [selectionView setBackgroundColor: [UIColor clearColor]];

    UIImage *image = [[UIImage alloc]init];
    image = [UIImage imageWithContentsOfFile:@"PlaceHolder.png"];
    UIImageView* blockView = [[UIImageView alloc] initWithImage:image];
    blockView.frame = CGRectMake(0, -5, 45, 45);

    if([[[_arrayForTable valueForKey:@"URL"] objectAtIndex:[indexPath row]] isEqualToString:@"No Image"] ) 
    {


        [selectionView addSubview:blockView];


    }
    else
    {
        NSString *path = [[_arrayForTable valueForKey:@"URL"] objectAtIndex:[indexPath row]];

        NSURL *url = [NSURL URLWithString:path];
        AsyncImageView *imageView = [[[AsyncImageView alloc] init] autorelease];
        imageView.frame = CGRectMake(0, -5, 45, 45);
        imageView.imageURL=url;
        [selectionView addSubview:imageView];


    }

否则条件工作完美他们有facebook的网址在表视图中显示图像但如果条件不工作它进入如果条件但图像没有显示PLZ帮助

2 个答案:

答案 0 :(得分:2)

UIImage *image = [UIImage imageNamed:@"PlaceHolder.png"];
UIImageView* blockView = [[UIImageView alloc] initWithImage:image];

/*
imageNamed: is to load the picture which is in bundle. pass in the picture name
imageWithContentsOfFile: need to pass in the whole address of the file
*/

答案 1 :(得分:1)

尝试

  UIImage *image = [UIImage imageNamed:@"yourfile.png"];

并将图像添加到imageView并检查图像文件是否适合您的项目