在我的故事板我有一个表视图。 我使用从JSON文件(在viewDidLoad中加载)加载的数据填充该表视图。UITableView重叠滚动
在我的UITableView中,我确实将“Prototype Cells”设置为1,因此我可以轻松选择一个附件。 我的原型单元有一个Seque到一个新的视图,需要显示所选项目的细节。
我填我的细胞编程方式使用这样的:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *videoTableIdentifier = @"VideoCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:videoTableIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:videoTableIdentifier];
UILabel * title = [[UILabel alloc] initWithFrame:CGRectMake(40,5, 240,20)];
[cell addSubview:title];
[title setText:[[videos objectAtIndex:indexPath.row] objectForKey:@"title"]];
UILabel * detail = [[UILabel alloc] initWithFrame:CGRectMake(40,28, 100,10)];
[cell addSubview:detail];
[detail setText:[NSString stringWithFormat:@"Year: %@", [[videos objectAtIndex:indexPath.row] objectForKey:@"year"]]];
[cell addSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:[[videos objectAtIndex:indexPath.row] objectForKey:@"image"]]]];
return cell;
}
当我开始滚动会发生以下情况:
所以我开始寻找解决的办法,我发现我必须设置: dequeueReusableCellWithIdentifier:videoTableIdentifier
为“无”。
虽然我这样做,这解决了我的问题,但是现在我原型单元配件和Seque都不见了,所以我不能导航到下一个视图了。
我找不到在互联网上的解决方案,所以我决定问这个。 如果有人可以帮忙,会很棒。
这就是我的想法,因为我已经阅读了有关回收细胞的一些信息,但是我找不到如何解决这个问题。只有文本重叠,图像保持不变,即使这也是子视图?! – ronnyrr
图像堆叠在另一个上面。如果它有帮助,请接受答案 –
实际上,您可以将if(cell == nil)条件中的addSubview代码移入其中,并且无需创建UITableViewCell的子类就可以正常工作。但我认为创建自定义子类仍然是一个更好的方法 – Lukas