本文介绍了TableView中图像的大小不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用来自URL的图像创建表格视图,但是直到我在行中按下图像时,图像才会调整为所有视图的大小.知道为什么会这样吗?这是一个自定义表格视图

I am creating a table view with images from an URL, but the images don´t re-size to all the view until I presset it in the row.any idea why that is happening?This is a custom tableview

我的代码是:

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

}

表格已正确填充,但是图像的开头尺寸不正确.

the table is correctly fill, but the image dont start with the correct size.

我尝试使用CGRectMake,但仍然无法正常工作.

I have tried use the CGRectMake but it still don t work.

谢谢.

推荐答案

我已经解决了这个问题...我在Xib文件中的tableviewcell内的视图大于tableviewcell,因此它开始时不正确(我现在不这样做),但现在该表已正确填充.

I have solve the problem...My view inside the tableviewcell in the Xib file was bigger than the tableviewcell, so it begins incorrectly (i don t now why), but now the table is correctly fill..

感谢所有人

这篇关于TableView中图像的大小不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 08:38
查看更多