UITableViewCell中的ImageView上选择改变(UItableViewCell im

2019-06-17 13:35发布

我使用加载的WebCache在Facebook用户的列表和它的作品充满了想象。 直到你选择其中的一个单元,然后它似乎要么改变内容模式,或者更可能它改变了UIImageView的帧的大小,而是根据画面的实际大小。 为了清楚起见,这里有一些屏幕

这里被装载http://img.photobucket.com/albums/v246/homojedi/Screenshot20120727114807.png

和一些图像的选择,你可以看到,他们似乎要跳转到原来的方面。 http://img.photobucket.com/albums/v246/homojedi/Screenshot20120727114827.png

按照预期,如果我滚动它们关闭屏幕回给他们,他们恢复到他们在开始的。

这是令人费解。 我还没有尝试的唯一的事情是子类的UITableView并设置有其布局子视图。 短的是有什么我可以做什么?

编辑:代码要求

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // typically you need know which item the user has selected.
    // this method allows you to keep track of the selection
    _indexPath = indexPath;

    [_indexPath retain];
}

Answer 1:

我已经面对完全一样的问题,因为你,我修复

这个问题是由原因你命名你的ImageView“ImageView的”

我不知道为什么

如果你改变你的ImageView的名称,比如“m_imageView”

问题固定

这是所有关于命名!



Answer 2:

我也碰到过这个问题,但我没有imageView我的自定义的UITableViewCell内的财产。

其实我也从我的ImageView对象连接额外的IBOutlet中的默认做出愚蠢的错误imageView的UITableViewCell的财产。 这是因为我最初命名我的图像视图imageView ,但后来我改变了它,忘掉出口。

除去出口之后,一切工作正常。



Answer 3:

万一别人和我一样,临到这个问题,其中上述非工作。

我也曾经有过一个名为我UIImageViewimageView但是 ,出于某种原因, 甚至将其改名后 ,问题依然存在。 我什么都试过了我能想到的,重置模拟器,清理项目,添加删除约束....

事实证明 ,简单地删除 UIImageView从故事板和拖动一个新的固定它。

不可能是预编译的问题,因为我清理项目。 去搞清楚。



Answer 4:

我是有这个问题,我解决它!

检查以确保您的合成在自定义TableViewCell的ImageView的属性。

忘了合成性(导致没有的getter / setter为IBOutlet中)。

这个主题是旧的,但希望帮助别人!



Answer 5:

// reason for this problem is UITableView cell's imageview initially has a default size later on it resize it self on select so following cab be a solution for this: (Using AFNetworking to set image/ You can adjust accordingly)

            __weak UItableViewCell *cellTemp = cell;

            [cell.imageView setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:strURL]]
                                  placeholderImage:[UIImage imageNamed:@"placeholder"]
        success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image)
            {
                cellTemp.imageView.image = image;

                CGRect frameRect = cellTemp.imageView.frame;
                frameRect.origin.y = (cellTemp.frame.size.height - image.size.height)/2;
                frameRect.size.width = image.size.width;
                frameRect.size.height = image.size.height;
                cellTemp.imageView.frame = frameRect;

                [cellTemp layoutSubviews]; 
    // this will fit your cell's label

            }
        failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error)
            {

            }];


Answer 6:

我相信你的问题是由于UIImageView的。 您应该设置一下图片 - cell.imageView.image = MYIMAGE。 不要设置highlightedImage。 设置contentMode维持图像的高宽比:cell.imageView.contentMode = UIViewContentModeScaleAspectFit ;,并验证contentStretch矩形是0,0,1,1(缺省值)。

这是可能的的tableView正在改变的UIImageView或框架的contentMode当它被选中(谁知道为什么原因)。 我想补充NSLogs两者willSelectRowAtIndexPath和didSelectRowAtIndexPath方法,示出了相同的信息:所述ImageView的帧时,contentMode值(作为一个整数)等。这些值不知何故一个或多个上的选择正在改变。



Answer 7:

添加到关于命名问题的答案:

正如有人说,与图像视图中的问题,即使重命名后仍然存在。 但它并不需要删除UIImageView从厦门国际银行或故事板。 您只需按住Ctrl键单击图像查看和删除财产连接imageView仍然存在。

链接原因imageView仍然存在似乎是对imageView您在代码中删除后,产权仍然可用。 它仍然存在,因为它是从继承UITableViewCell

最后一个提示,听起来很愚蠢,但我花了几分钟的时间来实现:显然全部使用代码属性名imageView仍然可以工作,但会导致奇怪的行为! 所以,要仔细检查有没有用旧属性名称左侧的代码。



Answer 8:

我有同样的问题,甚至尝试所有以前的答案后,他们没有解决。 后来我发现了的UITableViewController有多个未使用的插座,所以删除未使用的插座固定的问题。



Answer 9:

根据要求由塞巴斯蒂安 - 卢西扎克我没有拿出一个解决方案的调整,但现在有一个图像质量不一致,它只有当你触摸它更高的分辨率,奇怪,但不是那么糟糕,或noticable,反正这里是代码。

NB我使用SDWebImage异步加载图片

[cell.imageView setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:@"Icon.png"]success:^(UIImage *image) 
 {
     cell.imageView.image = [image resizeImage:image newSize:CGSizeMake(38, 38)];

 } failure:^(NSError *error) 
 {

 }];


Answer 10:

//如果子类的UITableViewCell,你可以摆脱这个问题的

- (void)layoutSubviews {

    [super layoutSubviews];
    self.imageView.bounds = CGRectMake(10,5,65,65);
    self.imageView.frame = CGRectMake(10,5,65,65);
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;

}


文章来源: UItableViewCell imageview changing on select