ios - 在 UITableView 的编辑模式下移动标题

标签 ios objective-c uitableview cocoa-touch

我有一个带有自定义单元格和自定义标题的 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/

相关文章:

ios - Swift 中宽度属性的问题

ios - Lockito 类应用程序,用于在 iOS 上模拟/伪造位置

ios - Swift dismiss modal view on tableView select(控制流的最佳实践)

iphone - EGOTableViewPullRefresh - 模拟 viewDidLoad 上的下拉

ios - 在不使用车辆的情况下测试 OBD iOS App

iPhone sdk-在 KALViewController 中保存最后选择的日期

ios - 如何使用 Tesseract OCR 改进文本识别?

ios - React Native 限制?

c++ - NSArray 如何取得 C++ 对象的所有权

ios - 检测 UITableView 的底部 "bounce"