我有一个带有自定义单元格和自定义标题的 UITableView,如下所示:
--------------------
| Header |
--------------------
| cell |
| cell |
| etc |
每当我将其置于编辑模式时,为了删除单元格,它看起来像这样
--------------------
| Header |
--------------------
- | cell
- | cell
- | etc
如您所见,表格单元格向右移动以为减号图标腾出空间。但是,标题保持在相同的位置。我如何将标题向右移动,以匹配下面的单元格 x 位置?
最佳答案
您可以在 -(UIView *)tableView:(UITableView *)tv viewForHeaderInSection:(NSInteger) 部分的页眉中添加标签,如下所示:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, self.tableView.bounds.size.width - 45,50)];
label.font = [UIFont systemFontOfSize:14];
label.backgroundColor = [UIColor greenColor];
if(self.tableView.editing && section==0)
{
label.frame = CGRectMake(0,0,self.tableView.bounds.size.width,150);
NSString *NewSection = @"My new header message in edit mode d\n\n OK";
label.text = NewSection;
}
else {
label.frame = CGRectMake(0,0,self.tableView.bounds.size.width,40);
label.text = [self tableView:tableView titleForHeaderInSection:section];
}
[sectionHeader addSubview:label]; 然后将其添加到您的标题 View 中
希望对你有帮助。
关于ios - 在 UITableView 的编辑模式下移动标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4251635/