2013-03-26 56 views
0

我试图加我在项目中加入图片我用下面的代码为它表视图中显示的图像是在项目

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]; 


    } 

else条件的工作完美,他们拥有Facebook的URL显示在表视图图像但如果没有工作,那么要在,如果是没有得到显示条件,但图像条件plz帮助

回答

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 
*/ 
+0

@ user2189388欢迎您 – 2013-03-26 10:26:27

1

尝试

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

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