TableView中的标题重复多次
我有一些问题,在屏幕上重复一些标题。 它似乎出现在我单击TableViewCell中的textView时,它会自动滚动以将单元格放在屏幕中间,并在所有这些过程中写入。 标题“重复”可以在页脚中,也可以在其他任何地方获取信息。
这是截图:
这是代码:
- (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函数中,添加那些行以防止在开始操作之前完成动画;
[CATransaction begin]; [CATransaction setCompletionBlock: ^{ [self.tableView beginUpdates]; [self.tableView endUpdates]; }]; [CATransaction commit];
您不需要对willDisplayHeaderView
的view参数执行任何操作,也不需要将任何内容转发给viewForHeaderInSection
或heightForHeaderInSection
的’ delegate
‘(这些是委托方法,因此您是委托)。 heightForHeaderInSection
应返回一个静态值,而不是UITableViewAutomaticDimension
,如果不使用自动布局,可能会导致布局问题。 你的’ sectionAtIndex
‘函数检索你的标题视图,但是使用UItableViewDataSource
函数’ titleForHeaderInSection
‘而不是’ viewForHeaderInSection
‘可能更容易,或者动态生成UILabels。