UITableView单元格中的ImageView在点击时更改大小?

3
当我加载页面时,它很正常,请查看下面的图片。 enter image description here 当我点击一行时,相应的图像以不同的大小显示,请查看下面的图片(当我点击第一行和第二行时)。 enter image description here 请帮助我解决这个问题。我正在使用SDWebImage从URL中进行懒加载图像。
我的代码:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;    //count of section
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [names count];    //count number of row from counting array hear cataGorry is An Array
}



- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *MyIdentifier = @"service";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:MyIdentifier]
        ;
    }

    // Here we use the provided setImageWithURL: method to load the web image
    // Ensure you use a placeholder image otherwise cells will be initialized with no image

   // cell.imageView.frame=CGRectMake(5,10,50,60);
    cell.imageView.layer.cornerRadius=8.0;
    cell.imageView.clipsToBounds=YES;
    cell.imageView.autoresizingMask=UIViewAutoresizingFlexibleHeight;
    [cell.imageView setImageWithURL:[NSURL URLWithString:[imaages objectAtIndex:indexPath.row]]placeholderImage:[UIImage imageNamed:@"Placeholder.png"]];
    cell.textLabel.text = [names objectAtIndex:indexPath.row];
    cell.backgroundColor=[UIColor clearColor];

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    return 80;

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}

通过使用自定义的UITableViewCell进行修复。 - Bangalore
你如何解决这个问题? - dieter
尝试点击上面的链接,它解决了我的问题:UItableViewCell imageview changing on select - Prasad Bulbule
2个回答

0

如果在表格视图加载完成后重新加载,图片将获得其应有的大小。

[self.tableview reloadData];

0

解决方案

将图像剪裁到子视图,并添加自动布局。

[cell.contentView.superview setClipsToBounds:YES];

对于自定义单元格,请选择您的图像并

enter image description here


这不是自定义单元格。 - Bangalore
imageView.autoResizingMask 设置为 UIViewAutoResizingNone - E-Riddie
嗯,我曾经遇到过这种情况,但那时我在一个非ARC项目中,在viewWillDisappear中释放了viewController。当你点击一个行时,你会怎么做? - E-Riddie
尝试删除if语句及其所有内容。 - E-Riddie
让我们在聊天中继续这个讨论:http://chat.stackoverflow.com/rooms/54365/discussion-between-3r1d-and-bangalore。 - E-Riddie

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接