Перемещение заголовка в режиме редактирования UITableView - PullRequest
4 голосов
/ 23 ноября 2010

У меня есть UITableView с настраиваемыми ячейками, а также с настраиваемым заголовком, например:

--------------------
|   Header         |
--------------------
|     cell         |
|     cell         |
|     etc          |

Когда бы я ни переводил его в режим редактирования, чтобы удалить ячейки, он выглядит так*

--------------------
|   Header         |
--------------------
-  |     cell        
-  |     cell        
-  |     etc      

Как видите, ячейки таблицы перемещаются вправо, чтобы освободить место для значков минус.Тем не менее, заголовок остается в той же позиции.Как бы я переместил заголовок вправо, чтобы он соответствовал расположению клеток ниже?

Ответы [ 3 ]

0 голосов
/ 08 августа 2016

Вы можете добавить метку в свой заголовок в - (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]; Затем добавьте его в свой заголовок

Надеюсь, это поможет вам.

0 голосов
/ 08 августа 2016
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView* viewObj = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 40]; 

UILabel *headerLabel = [[UILabel alloc] init];

headerLabel.font = [UIFont systemFontOfSize:14];
headerLabel.backgroundColor = [UIColor greenColor];
if(self.tableView.editing && section==0)
{
   headerLabel.frame = CGRectMake(cellpositionX,0,self.tableView.bounds.size.width - cellpositionX,40);
    NSString *NewSection = @"My new header message in edit mode d\n\n OK";
    headerLabel.text = NewSection;
}
else   {
  headerLabel.frame = CGRectMake(0,0,self.tableView.bounds.size.width,40);  
headerLabel.text = [self tableView:tableView titleForHeaderInSection:section];
   }
[viewObj addSubview:headerLabel];
return viewObj;}

В приведенном выше коде вы можете передать значение x в ячейкуX.

Также каждый раз, когда TableView начинает и заканчивает редактирование.вам нужно перезагрузить TableView

Я надеюсь, что это решит вашу проблему

0 голосов
/ 25 ноября 2010

Создан другой кончик для заголовка режима редактирования, а затем отображается только при редактировании:

-(UIView *)tableView:(UITableView *)tv viewForHeaderInSection:(NSInteger)section {
// CustomHeader creates the header view
CustomHeader *tableHeader;  
if (self.tableView.editing) 
{
    tableHeader = (CustomHeader *)[CustomHeader headerFromNibNamed:@"CustomHeaderEditMode"];        
} else {
    tableHeader = (CustomHeader *)[CustomHeader headerFromNibNamed:@"CustomHeader"];
}
return tableHeader;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...