【发布时间】:2014-09-04 10:39:09
【问题描述】:
当我滚动表格视图时,会出现这种类型的重叠
我在 CellForRow AtIndexPath 方法中编写以下代码,我以编程方式创建 tableview...
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
NSDictionary *info = [ASSETHELPER getGroupInfo:_groupArray[indexPath.row]];
UIImageView *view;
if (indexPath.row % 2) {
view=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"dark_bg"]];
}else{
view=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"light_bg"]];
}
cell.backgroundView=view;
UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
imgView.backgroundColor=[UIColor clearColor];
[imgView.layer setCornerRadius:25];
[imgView.layer setMasksToBounds:YES];
[imgView.layer setBorderColor:[UIColor whiteColor].CGColor];
[imgView setImage:[info objectForKey:@"thumbnail"]];
[cell.contentView addSubview:imgView];
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(80, 20, 200, 30)];
[label setText:[info objectForKey:@"name"]];
[cell.contentView addSubview:label];
return cell;
}
【问题讨论】:
-
我们不是巫师或通灵者。添加一些代码,以及更多细节。
-
您没有正确处理单元格的可重用性。在此处发布您的 cellPathForRowAtIndexPath 代码。
-
好多了。对不起,如果我之前听起来很粗鲁。这里的问题是
[cell.contentView addSubview:label];。每次调用cellForRowAtIndexPath:时,您每次都添加一个新标签。由于单元格被重复使用,因此之前添加的标签永远不会被删除。
标签: objective-c ios7 uicollectionview alassetslibrary alasset