2011-05-30 75 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