2015-05-07 97 views
0

我正在努力解决以下问题: 我正在从Json下载标题和imageUrl,并使用以下方法将它们设置在我的UITableView自定义单元格中:UITableView单元格UIImageView在选中时随机更改他的框架

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Retrieve cell 
    NSString *cellIdentifier = @"cell"; 
    UITableViewCell *categoryCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    categoryCell.textLabel.lineBreakMode = NSLineBreakByWordWrapping; 
    categoryCell.textLabel.numberOfLines = 0; 

    // Get the location to be shown 
    RecipesList *item = _feedRecipesList[indexPath.row]; 




    // Get references to labels of cell 
    categoryCell.textLabel.text = item.name; 
    item.urlImg = [item.urlImg stringByReplacingOccurrencesOfString:@" " withString:@"%20"]; 
    [categoryCell.imageView sd_setImageWithURL:[NSURL URLWithString:item.urlImg] 
       placeholderImage:[UIImage imageNamed:@"Placeholder.png"]]; 



    return categoryCell; 
} 

一切工作正常,但当我选择一个单元格(所以它被突出显示)单元格的UIImageView框架更改它的大小没有任何理由。起初我使用的基本单元,我认为这个问题是由导致,所以我试着用定制的小区,在我的.m文件添加以下代码自定义类:

- (void)layoutSubviews { 
[super layoutSubviews]; 

self.imageView.frame = CGRectMake(0,0,55,55); 

//Any additional setting that you want to do with image view 

[self.imageView setAutoresizingMask:UIViewAutoresizingNone]; 

} 

它调整的UIImageView但再次如果我选择一个单元格的图像帧更改。

有没有人有同样的问题?

而且为了创建延迟加载我使用库SDWebImage,但我不认为问题与此有关。

回答

0

奇怪的行为。只是一些建议,试试这个

self.autoresizesSubviews = NO; 
self.contentView.clipsToBounds = YES; 
self.imageView.contentMode = UIViewContentModeScaleAspectFit; 
+0

试过但0运气:(泰帮助无论如何! – Signo

0

上帝,我终于解决了这一点,而不是使用我添加了一个UIImageView,为了创建一个自定义单元格一个UILabel到单元格的标准电池元件,然后按顺序正确地显示图像我已经添加了LayoutSubviews方法cellImg.contentMode = UIViewContentModeScaleAspectFill;

相关问题