2015-12-22 6 views
0

У меня есть простой UITableViewController, который содержит около 40 UITableViewCells и UITableViewController встроен в UITabBarController. UITableViewController создан в Раскадровке.UITableViewCell прокручивает пользовательский заголовок заголовка UITableView

Я переопределяю обычай UITableViewHeader Текст, чтобы у меня было несколько руководств для пользователей. Я заметил, некоторые действительно странное поведение с этим, как представлено следующими изображениями:

enter image description here

enter image description here

Как можно видеть, UITableView прокручивается, но текст заголовка остается там, и это выглядит ужасно.

Вот как я настройка пользовательского заголовка:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    // Custom label for the section header titles 
    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(25, 0, tableView.frame.size.width, 110)]; 
    label.textAlignment = NSTextAlignmentCenter; 
    label.textColor = [UIColor whiteColor]; 
    label.numberOfLines = 0; 

    [label setFont:[UIFont systemFontOfSize:17.0]]; 

    if (section == 0) 
    { 
     label.text = @" Add to this by marking a leaflet or video as a favourite.\n\nYou can do this by swiping left on any leaflet or video cell."; 
    }  
    return label; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 

    CGFloat headerHeight = 0; 

    headerHeight = 110; 

    return headerHeight; 

} 

Я работал с различными размерами, но независимо от того, что я делаю, он все еще ведет себя таким же образом.

Если у кого-то есть какие-то мысли или рекомендации по этому вопросу, это было бы действительно оценено. Я просто хочу, чтобы текст заголовка также прокручивался вверх с табличным представлением и поэтому был скрыт от просмотра при прокрутке.

+0

это Lable вопрос цвет фона. Просто установите label.backgroundColor = [UIColor grayColor]; in viewForHeaderInSection. –

+0

Спасибо @ Dev.RK - принятый ответ работал в этом случае, не меняя цвет фона. – amitsbajaj

ответ

1

Вы можете добавить свой заголовок как tableHeaderView, как это:

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(25, 0, self.tableView.frame.size.width, 110)]; 
    label.textAlignment = NSTextAlignmentCenter; 
    label.textColor = [UIColor blackColor]; 
    label.numberOfLines = 0; 
    [label setFont:[UIFont systemFontOfSize:17.0]]; 
    label.text = @" Add to this by marking a leaflet or video as a favourite.\n\nYou can do this by swiping left on any leaflet or video cell."; 
    self.tableView.tableHeaderView = label; 
} 
+0

Большое спасибо @lorenzoiliveto - я понятия не имел, что могу это сделать и с вашим кодом в viewDidLoad вместо того, чтобы отдельно переопределять метод, это устранило проблему. Еще раз спасибо за вашу быструю помощь! – amitsbajaj

1
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 
// Custom label for the section header titles 
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 110)]; 
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(25, 0, tableView.frame.size.width, 110)]; 
label.textAlignment = NSTextAlignmentCenter; 
label.textColor = [UIColor whiteColor]; 
label.numberOfLines = 0; 

[label setFont:[UIFont systemFontOfSize:17.0]]; 

if (section == 0) { 
    label.text = @" Add to this by marking a leaflet or video as a favourite.\n\nYou can do this by swiping left on any leaflet or video cell."; 
}  
[view addSubView:label]; 
[view setBackgroundColor:[UIColor blueColor]]; // the color for background 
return view;} 
+0

Большое спасибо @vaibby - это действительно полезно, но другой принятый ответ работал в этом случае. Еще раз спасибо – amitsbajaj

+0

u может дать зеленый тик для ответа тоже. – vaibby