2013-03-26 46 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並檢查圖像文件是否已添加到您的項目中