【问题标题】:UITableView cell Imageview changing its size on click?UITableView 单元格 Imageview 在单击时更改其大小?
【发布时间】:2014-07-14 01:02:55
【问题描述】:

当我加载页面时,请检查下面的图片

当我点击一行时,相应的图片会以不同的尺寸显示,请检查下图(当我点击第一行和第二行时)

请帮我解决这个问题。这里使用 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{
}

【问题讨论】:

标签: ios objective-c image uitableview


【解决方案1】:

如果您在完成加载后重新加载 tableview,则图像将获得它应该具有的大小

[self.tableview reloadData];

【讨论】:

    【解决方案2】:

    解决方案

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

    [cell.contentView.superview setClipsToBounds:YES];
    

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

    【讨论】:

    • 这不是客户单元
    • imageView.autoResizingMask 设置为UIViewAutoResizingNone
    • 嗯,我曾经发生过这样的事情,但我在非 ARC 项目上,我正在 viewWillDisappear 上发布 viewController。点击一行时你会做什么?
    • 尝试删除 if 语句及其所有内容
    猜你喜欢
    • 2020-07-13
    • 2012-09-27
    • 1970-01-01
    • 2011-07-16
    • 2019-02-01
    • 2011-12-18
    • 1970-01-01
    • 2016-04-21
    • 1970-01-01
    相关资源
    最近更新 更多