2011-05-30 96 views
2

我使用URL中的圖像創建表視圖,但圖像不會重新調整大小以適合所有視圖,除非我在該行中預先設置了大小。 任何想法爲什麼發生這種情況? 這是一個自定義的tableviewTableView中的圖像大小不正確

我的代碼是:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    static NSString *CellIdentifier = @"Celula_Noticias"; 

    Celula_Noticias *cell = (Celula_Noticias*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 

    NSArray * top= [[NSBundle mainBundle] loadNibNamed:@"Celula_Noticias" owner:self options:nil]; 

    for(id currentObject in top){ 
     if ([currentObject isKindOfClass:[Celula_Noticias class]]) { 
      cell= (Celula_Noticias *) currentObject; 
      break; 
     } 

    } 


} 


cell.Image_Noticias_1.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[[noticias objectAtIndex:indexPath.row ] objectAtIndex:0]]]]; 

cell.Image_Noticias_2.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[[noticias objectAtIndex:indexPath.row ] objectAtIndex:2]]]]; 

cell.Titulo_Noticias_1.text=[[noticias objectAtIndex:indexPath.row ] objectAtIndex:1]; 
cell.Titulo_Noticias_2.text=[[noticias objectAtIndex:indexPath.row ] objectAtIndex:3]; 


return cell; 

}

表中填寫正確,但圖像不正確大小開始。

我試過使用CGRectMake,但它仍然沒有工作。

謝謝。

+0

發佈一些代碼..... – 2011-05-30 16:25:25

+0

顯示代碼,您從URL檢索圖像,並將其設置在圖像視圖。 – rptwsthi 2011-05-31 06:31:15

回答

0

我必須解決這個問題。 ..我在廈門國際銀行文件tableviewcell內 觀點比tableviewcell大,所以它開始不正確的(我現在唐噸爲什麼),但現在的表是正確填寫..

感謝所有

4

創建一個函數來進行後期處理下載的鏡像:

- (UIImage*)postProcessImage:(UIImage*)image 
{ 
     CGSize itemSize = CGSizeMake(50, 50); 

     UIGraphicsBeginImageContext(itemSize); 
     CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height); 
     [image drawInRect:imageRect]; 
     UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext(); 
     return newImage; 
} 

功能上面會給你50 * 50回一個漂亮的圖像。

然後,你可以這樣做:

UIImage* downloadedImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"...url goes here..."]]]; 
UIImage* newImage = [self posProcessImage:downloadedImage]; 
cell.imageView.image=newImage 
+0

它仍然不工作...我必須觸摸uiimageview以顯示所有圖像... – DaSilva 2011-05-31 10:42:49

+0

謝謝你的解決方案:) – neham 2014-02-12 06:38:46

0

我想,您使用的是UIImageView,你應該改變它的屬性方面配合(如果沒有的話)

+0

沒有..它仍然不工作..物業規模填補比較好我認爲.. – DaSilva 2011-05-31 10:09:32

相關問題