2011-09-21 26 views
-1

iam開發一個應用程序,我使用三個imageviews爲表中的單個行。前兩個圖像加載成功。在加載第三個圖像時,圖像將變成黑色。請告訴我如何處理這個one。下面是imageview聲明的代碼。如何處理imageviews?

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
     UITableViewCell *cell=[[[UITableViewCell alloc]init] autorelease]; 
     tableview1.separatorStyle=UITableViewCellSeparatorStyleNone; 
    if(indexPath.row==0) 
    { 
     image1=[[[UIImageView alloc]initWithFrame:CGRectMake(12, 8, 90, 90)]autorelease]; 
     image1.frame=CGRectMake(12, 8, 90, 90); 
     [image1.layer setBorderWidth:1.0f]; 
     [image1.layer setBorderColor:[[UIColor grayColor] CGColor]]; 
     [image1.layer setCornerRadius:1.0f]; 
     image1.layer.masksToBounds = YES; 
     image1.userInteractionEnabled=YES; 
     image1.tag=1; 

     [image1 setContentMode:UIViewContentModeScaleToFill]; 
     if([[odrdata stringForKey:@"keyTo1Image"] isEqualToString:@""]) 
     { 

     } 
     else 
     { 
    image1.image=[UIImage imageWithContentsOfFile:[odrdata stringForKey:@"keyTo1Image"]]; 

     } 
     [cell.contentView addSubview:image1]; 

    image2=[[[UIImageView alloc]initWithFrame:CGRectMake(114, 8, 90, 90)]autorelease]; 
     image2.frame=CGRectMake(114, 8, 90, 90); 
     [image2.layer setBorderWidth:1.0f]; 
     [image2.layer setBorderColor:[[UIColor grayColor] CGColor]]; 
     [image2.layer setCornerRadius:1.0f]; 
     image2.layer.masksToBounds = YES; 
     image2.userInteractionEnabled=YES; 
     image2.tag=1; 

     [image2 setContentMode:UIViewContentModeScaleToFill]; 
     if([[odrdata stringForKey:@"keyTo2Image"] isEqualToString:@""]) 
     { 

     } 
     else 
     { 
    image2.image=[UIImage imageWithContentsOfFile:[odrdata stringForKey:@"keyTo2Image"]]; 

     } 
     [cell.contentView addSubview:image2]; 

    image3=[[[UIImageView alloc]initWithFrame:CGRectMake(216, 8, 90, 90)]autorelease]; 
     image3.frame=CGRectMake(216, 8, 90, 90); 
     [image3.layer setBorderWidth:1.0f]; 
     [image3.layer setBorderColor:[[UIColor grayColor] CGColor]]; 
     [image3.layer setCornerRadius:1.0f]; 
     image3.layer.masksToBounds = YES; 
     image3.userInteractionEnabled=YES; 
     image3.tag=3; 

     [image3 setContentMode:UIViewContentModeScaleToFill]; 
     if([[odrdata stringForKey:@"keyTo3Image"] isEqualToString:@""]) 
     { 

     } 
     else 
     { 
    image3.image=[UIImage imageWithContentsOfFile:[odrdata stringForKey:@"keyTo3Image"]]; 
     } 
     [cell.contentView addSubview:image3]; 

fsttapGesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handlefstTap:)]; 
     fsttapGesture.delegate=self; 
     [image1 addGestureRecognizer:fsttapGesture]; 

sndtapGesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handlesndTap:)]; 
     sndtapGesture.delegate=self; 
     [image2 addGestureRecognizer:sndtapGesture]; 

trdtapGesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handletrdTap:)]; 
     trdtapGesture.delegate=self; 
     [image3 addGestureRecognizer:trdtapGesture]; 

     return cell; 
    } 

}

+0

我只在這裏看到一個圖像視圖。你在談論的另外兩個在哪裏? – LucasTizma

+0

像這樣,另外兩個圖像將以水平方式添加到單元格的不同位置。 –

+0

請顯示所有圖片瀏覽的所有相關代碼。否則,幾乎不可能知道發生了什麼問題。 – LucasTizma

回答

0

你確定該文件存在keyTo3Image?可能發生的情況是,圖像視圖無法在您在該字符串中指定的路徑中找到圖像。檢查它是否指向一個文件。爲了驗證這一點,改變image3backgroundColor屬性,看看它的變化:

image3.backgroundColor = [UIColor redColor]; 

如果變成紅色,則意味着圖像找不到,所以它只是顯示一個空的圖像視圖。

+0

它執行更改後顯示圖像。 –