将子视图添加到UITableViewCell [英] add subviews to UITableViewCell
本文介绍了将子视图添加到UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将子视图添加到UITableViewCell时遇到问题。
当桌面尺寸低于iPhone尺寸时,它正在工作。
I have trouble when I add subviews to UITableViewCell. It's working when the table size is below the iPhone size.
但是当尺寸较大时,当我滚动时会产生一些像这样的可怕效果:
But when the size is bigger, it makes some horrible effect like this when I'm scrolling :
它应该是这样的:
然后我认为它来自细胞重用。
以下是我的代码示例:
Then I think it comes from the cell reuse. Here is a sample of my code :
- (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;
}
子视图是类的属性,并在方法viewDidLoad中配置。
如果你能告诉我我做错了什么,那将是一种解脱。
The subviews are attributs of the class, and configured in the method viewDidLoad. If you can tell me what i'm doing wrong, that would be such a relief.
推荐答案
switch (indexPath.row) {
case 0:
if (![cell.contentView viewWithTag:11]) {
titleEvent.tag = 11;
[cell.contentView addSubview:titleEvent];
}
break;
case 1:
if (![cell.contentView viewWithTag:11]) {
logoAsso.tag = 11;
[cell.contentView addSubview:logoAsso];
}
像这样适用于所有开关案例
like this do for all switch cases
这篇关于将子视图添加到UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文