TableView 中的标题重复多次 [英] Header in TableView is repeating multiple times

查看:30
本文介绍了TableView 中的标题重复多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一些在屏幕上重复出现的标题的问题.当我单击 TableViewCell 中的 textView 时,它似乎出现,它会自动滚动以将单元格放在屏幕中间,然后我在整个过程中写入它.重复"的标题可以位于页脚中,也可以位于其他任何位置以获取信息.

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.

这是截图:

代码如下:

- (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;
}

推荐答案

在 textDidChange 函数中,添加该行以防止动画在开始操作之前完成或未完成;

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];

这篇关于TableView 中的标题重复多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆