我正在使用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];
}
我面临与你完全相同的问题,我解决了
问题是由你命名你的imageView“imageView”
我不知道为什么
如果你改变你的imageView名称,如“m_imageView”
问题已解决
这一切都与命名有关!
//如果你是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
属性。
事实上,我确实通过将我的imageView对象中的额外IBOutlet连接到UITableViewCell的默认imageView
属性而犯了一个愚蠢的错误。这是因为我最初命名我的图像视图imageView
,但后来我改变了它,忘记了插座。
拆下插座后,一切正常。
以防其他人,像我一样,遇到这个问题,而上述情况并非如此。
我也把我的UIImageView
命名为:imageView
。但是,由于某种原因,即使重命名后,问题仍然存在。我尝试了我能想到的一切,重置模拟器,清洁项目,添加删除约束....
事实证明,只需从故事板中删除UIImageView
并拖动一个新的固定它。
因为我清理了项目,所以不能成为预编译的问题。去搞清楚。
我遇到了这个问题,我解决了!
检查以确保在自定义TableViewCell中合成了imageView属性。
我忘了合成一个属性(导致IBOutlet没有getter / setter)。
这个话题很老但希望能帮到别人!
// 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)
{
}];
我相信你的问题是由于UIImageView。你应该设置一次图像 - cell.imageView.image = myImage。不要设置highlightImage。设置contentMode以保持图像的宽高比:cell.imageView.contentMode = UIViewContentModeScaleAspectFit;,并验证contentStretch rect是0,0,1,1(默认值)。
当tableView被选中时,它可能会改变UIImageView或其框架的contentMode(谁知道原因)。我会将NSLogs添加到willSelectRowAtIndexPath和didSelectRowAtIndexPath,显示相同的信息:imageView框架,contentMode值(作为整数)等。不知何故,这些值中的一个或多个在选择时发生变化。
添加有关命名问题的答案:
如上所述,即使重命名后,图像视图的问题仍然存在。但是不需要从xib或storyboard中删除UIImageView
。您只需按住Ctrl键单击图像视图,然后删除仍存在的属性imageView
的连接。
与imageView
链接仍然存在的原因似乎是在您的代码中删除imageView
属性后仍然可用。它仍然存在,因为它继承自UITableViewCell
。
最后一个暗示听起来很愚蠢,但花了我几分钟才意识到:显然所有使用属性名称imageView
的代码仍然可以工作,但会导致奇怪的行为!因此请仔细检查是否没有使用旧属性名称的代码。
我遇到了同样的问题,即使在尝试了之前的所有答案之后,也没有一个能够解决问题。后来我发现UITableViewController有多个未使用的Outlet,所以删除未使用的Outlets解决了这个问题。
根据sebastian-Luczak的要求,我确实提出了一个调整大小的解决方案,但是现在有一个图像质量不一致,只有当你触摸它时才会获得更高的分辨率,奇怪但不是那么糟糕或者说不明显,无论如何这里是代码。
N.B我正在使用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)
{
}];