[英]Offset appears in image content when scrolling UITableView
I am getting some strange behaviour when scrolling a TableView of custom UITableView cells. 滚动自定义UITableView单元格的TableView时出现一些奇怪的行为。
When the app first opens, the content is fine: 首次打开应用程序时,内容很好:
But if I scroll my view some offsets appear in the embedded UIImageViews: 但是,如果我滚动视图,则嵌入式UIImageViews中会出现一些偏移量:
I have removed all layout constraints, and the problem still occurs. 我已经删除了所有布局约束,但问题仍然存在。
I am at loss for reasons why this happens; 由于这种原因,我感到茫然。 any help is welcomed!
欢迎任何帮助!
Here's my cellForRowAtIndexPath
code: 这是我的
cellForRowAtIndexPath
代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *StrechCellIdentifier = @"StrechCell";
//Place regular strechable cells.
GFStrechCell *cell = [tableView dequeueReusableCellWithIdentifier:StrechCellIdentifier];
if (cell == nil) {
cell = (GFStrechCell*) [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:StrechCellIdentifier];
}
cell.nameLabel.text = @"Chez Julien";
cell.descriptionLabel.text = @"A yummy place!";
cell.descriptionLabel.hidden = YES;
[cell.restaurantImage setImage:[UIImage imageNamed:[NSString stringWithFormat:@"restaurant%i.png", (indexPath.row%5 + 1)]]];
if(indexPath.row % 2 == 0){
[cell.favoriteButton.imageView setImage:[UIImage imageNamed:@"favoriteButtonPressed.png"]];
} else {
[cell.favoriteButton.imageView setImage:[UIImage imageNamed:@"favoriteButton.png"]];
}
return cell;
}
GFStrechCell
is just a simple subclass of call with elements pointing to IBOutlets in storyboard: GFStrechCell
只是调用的一个简单子类,其元素指向情节GFStrechCell
中的IBOutlets:
That's odd, try this out just to see if it works 奇怪,请尝试一下以查看其是否有效
Below: 下面:
[cell.restaurantImage setImage:[UIImage imageNamed:[NSString stringWithFormat:@"restaurant%i.png", (indexPath.row%5 + 1)]]];
Try adding: 尝试添加:
CGRect restaurantImageFrame = cell.restaurantImage.frame;
restaurantImageFrame.origin = CGPointZero; //or whatever it should be
cell.restaurantImage.frame = restaurantImageFrame;
This will set the image's origin to (0,0). 这会将图像的原点设置为(0,0)。
Edit: you could also try adding the following line instead. 编辑:您也可以尝试添加以下行。
[cell.restaurantImage sizeToFit];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.