我向UITableViewCell添加子视图时遇到了问题。 当桌子尺寸低于iPhone尺寸时,它正在工作。向UITableViewCell添加子视图
但是当规模较大,这使得一些像这样的恐怖效果,当我滚动:
它应该是这样的:
那么我认为这来自细胞再利用。 这里是我的代码的示例:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *kCellIdentifier = @"UITableViewCellStyleSubtitle";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
if (cell == nil) {
//construct the cell
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:kCellIdentifier] autorelease];
//clear the previuous content
NSLog(@"Il y a %d subviews", [[[cell contentView] subviews] count]);
//[[[cell contentView] subviews] makeObjectsPerformSelector: @selector(removeFromSuperview)];
NSLog(@"Il y a %d subviews", [[[cell contentView] subviews] count]);
[[cell textLabel] setBackgroundColor:[UIColor clearColor]];
[cell setSelectionStyle:UITableViewCellEditingStyleNone];
}
switch (indexPath.row) {
case 0:
[cell addSubview:titleEvent];
break;
case 1:
//load the owner logo
[cell addSubview:logoAsso];
break;
case 2:
//StartDate
[cell addSubview:clockImage];
break;
case 3:
//EndDate
[cell addSubview:clockEndImage];
break;
case 4:
//Address
[cell addSubview:adress];
break;
case 5:
//map
[cell addSubview:map];
break;
case 6:
//header
[Graphism configureSeparationCell:cell];
break;
case 7:
//descritpion
[cell addSubview:descriptionEvent];
break;
default:
break;
}
return cell;
}
的子视图是类的attributs,和在该方法中viewDidLoad中配置。 如果你能告诉我我做错了什么,那会是一种解脱。