滚动隐藏时的iOS不起作用

时间:2014-09-16 13:54:04

标签: ios uitableview scroll

我的目标是当价值为零时,标签应该消失。      在滚动其工作正常但滚动所有标签出现之前      而且我不知道为什么?       您可以在下面找到我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ORGContainerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ORGContainerCell"];
if(cell==nil){
cell = [[ORGContainerCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ORGContainerCell"];
}
UILabel *headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(293, 4, 27, 95)]; 
UIImageView *labelBackground = [[UIImageView alloc]
                                initWithImage:[UIImage imageNamed:@"SUB TITLE BG.png"]];
Channel* getchannel = [categorieArray objectAtIndex:indexPath.section ];
NSMutableArray * getsub = getchannel.SubChannel;
if(getsub==nil){
  tableView.frame = CGRectMake(0, 20, 320, 490);
    headingLabel.hidden=YES;
    headingLabel.alpha = 0;
}else{
     headingLabel.alpha = 1;
    [cell addSubview:headingLabel];
Channel *val =  [getsub objectAtIndex:indexPath.row ];
headingLabel.text = val.ChannelName;
headingLabel.textColor = [UIColor orangeColor];
headingLabel.textAlignment = NSTextAlignmentCenter;
headingLabel.tag = 10;
headingLabel.backgroundColor = [UIColor clearColor];
headingLabel.font = [UIFont fontWithName:@"MarkerFelt-Thin" size:14.0];
headingLabel.hidden = NO;
headingLabel.highlighted = YES;
headingLabel.highlightedTextColor = [UIColor blueColor];
// headingLabel.lineBreakMode = YES;
headingLabel.numberOfLines = 0;
headingLabel.lineBreakMode = UILineBreakModeCharacterWrap;
headingLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"SUB TITLE BG.png"]];
// [headingLabel addSubview:labelBackground];
}
if(indexPath.section%2==0){
cell.strdatefromfirst = @"paire";
cell.backgroundColor =RGB(234, 234, 234);
}else{
cell.strdatefromfirst = @"impaire";
cell.backgroundColor =  RGB(196, 195, 194);  
}
NSDictionary *cellData = [self.sampleData objectAtIndex:[indexPath section]];
NSArray *articleData = [cellData objectForKey:@"articles"];
[cell setCollectionData:articleData];
return cell;
}

1 个答案:

答案 0 :(得分:0)

我怀疑这是因为细胞一旦滚出屏幕就会被重复使用。当dequeue ...方法返回单元格时,您之前添加为子视图的headingLabel不会被删除。所以你看到" old" headingLabels。就个人而言,我会将headingLabel作为属性添加到您的ORGContainerCell子类中,并将其作为您的单元格的子视图添加到Storyboard / XIB或init中。然后,您不需要在cellForRowAtIndexPath中每次都分配/ init。您可以将headingLabel.xxx更改为cell.headingLabel.xxx。另外,我认为在cellForRowAtIndexPath的中间调整tableView的框架是不明智的。