0
这是使用在“的cellForRowAtIndexPath”UITableView的重复行的
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* cellIdentifier = @"OBBirthControlMethodsTableCell";
OBCustomDetailCell *cell = (OBCustomDetailCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
NSLog(@"cell id - %@",cell.subviews);
CGRect frame = [tableView rectForRowAtIndexPath:0];
if(nil == cell)
{
cell = [[[OBCustomDetailCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
if (indexPath.row != 3)
{
//Setting the basic template
UIView *template = [[UIView alloc] init];
template.tag = indexPath.row+10;
NSLog(@"path index = %d",indexPath.row);
UIImageView *templateImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,
200,
frame.size.height)];
UILabel *templateLabel = [[UILabel alloc] initWithFrame:CGRectMake(templateImage.frame.size.width+20,
0,
cell.frame.size.width - templateImage.frame.size.width+20,
frame.size.height)];
[template addSubview:templateImage];
[template addSubview:templateLabel];
[cell.contentView addSubview:template];
}
}
UIView *templateView = [cell.contentView viewWithTag:indexPath.row + 10];
if (templateView)
{
NSLog(@"Gotten a templateView object");
if (indexPath.row == 0)
{
templateView.frame = frame;
for (UIView *view in templateView.subviews)
{
if ([view isKindOfClass:[UIImageView class]])
{
[(UIImageView *)view setImage:[UIImage imageNamed:@"baby.jpeg"]];
}
else if ([view isKindOfClass:[UILabel class]])
{
[(UILabel *)view setText:@"This is not working"];
}
}
}
else
{
templateView.frame = CGRectMake(0, 50,
frame.size.width,
frame.size.height);
}
}
return cell;
}
代码IM但问题是,新的电池给我相同的值OS旧的小区是出列,一旦你的新细胞向下滚动..
编辑 重复的细胞正在创建只要我们向下滚动,与第一小区相同瓦莱斯一个新的小区..
- 我想创建仅用于选择行()..if(indexPath.row!= 3)的UIView
- 我想在某些行中UIView的位置不同。if (indexPath.row == 0)
什么是不工作?文字没有被更新? 'indexPath.row == 3'上的单独单元格不工作?它是什么? – 2012-07-16 06:20:19
我已经添加了更清晰的问题解释 – 2012-07-16 06:23:03
**您何时以及何时从单元格中移除了不需要的**模板**视图?**因为已出队的单元格具有此视图并且您似乎添加了两个或更多为相同的单元格添加模板“UIView”的新实例,而不删除它们中存在的一个。你只是在浪费记忆,而你却让自己头痛。你为什么不为不同种类的细胞使用不同'cellID'的不同定制细胞?这个解决方案非常粗糙... – holex 2012-07-17 10:31:42