1

I have a problem with some headers that are repeating on the screen. It seems to appear when I click in a textView in a TableViewCell, it scrolls automatically to put the cell in the middle of the screen, and I write in it during all that process. The header "repeated" can be in the footer, or anywhere else for info.

Here is the screenshot:![enter image description here

Here is the code:

- (NSString *)tableView:(__unused UITableView *)tableView titleForHeaderInSection:(NSInteger)index //HEADER
{
    return [[self sectionAtIndex:index].header description];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{

    UILabel *myLabel = [[UILabel alloc] init];
    myLabel.frame = CGRectMake(12, 0, tableView.frame.size.width, 25);
    myLabel.font = sectionFont;
    myLabel.textColor = sectionColor;
    myLabel.backgroundColor = colorSegment;
    myLabel.text = [self tableView:tableView titleForHeaderInSection:section];

    UIView *headerView = [[UIView alloc] init];
    [headerView addSubview:myLabel];

    return headerView;
}
ΩlostA
  • 2,501
  • 5
  • 27
  • 63

2 Answers2

3

You shouldn't need to do anything to the view argument in willDisplayHeaderView, or forward anything to the 'delegate' in viewForHeaderInSection or heightForHeaderInSection (those are delegate methods so you are the delegate). heightForHeaderInSection should return a static value, not UITableViewAutomaticDimension, which can cause layout problems if not using auto layout. Your header views are retrieved by your 'sectionAtIndex' function, but it might be easier to use the UItableViewDataSource function 'titleForHeaderInSection' instead of 'viewForHeaderInSection', or generate UILabels on the fly.

Jack
  • 13,571
  • 6
  • 76
  • 98
FryAnEgg
  • 493
  • 4
  • 12
  • I removed all the willDisplayHeaderView, heightForHeaderInSection, etc... and only let the viewForHeaderInSection with the UILabel init, and the titleForHeaderInSection with changing color and font, and the titleForHeaderInSection function and it does exactly the same thing. Any ideas ? – ΩlostA May 04 '17 at 13:40
  • If you use viewForHeaderInSection, you only need to implement heightForHeaderInSection and return a static value. The other problem I see is you get the title for viewForHeaderInSection from titleForHeaderInSection, and vice-versa. Save your titles in an array in your data source, load from that in viewForHeaderInSection, eliminate titleForHeaderInSection, and implement heightForHeaderInSection. – FryAnEgg May 05 '17 at 16:06
1

In textDidChange function, add that lines to prevent the animation to be finished or not before begining opération;

 [CATransaction begin];

    [CATransaction setCompletionBlock: ^{

        [self.tableView beginUpdates];

        [self.tableView endUpdates];

    }];

    [CATransaction commit];
dt dino
  • 1,194
  • 6
  • 19