我有一个简单的 UITableViewController
,它包含大约 40 个 UITableViewCells
,UITableViewController
嵌入到 UITabBarController
中。 UITableViewController
在 Storyboard 中创建。
我正在覆盖自定义 UITableViewHeader
文本,以便我可以为用户提供一些指南。我注意到一些非常奇怪的行为,如下图所示:
可以看出,UITableView
滚动了,但标题文本仍保留在那里,看起来很糟糕。
这是我设置自定义 header 的方式:
- (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;
}
我使用过不同的尺寸,但无论我做什么,它的行为方式仍然相同。
如果有人对此有任何想法或指导,那将不胜感激。我只希望标题文本也随着表格 View 向上滚动,因此在滚动时从 View 中隐藏。
最佳答案
您可以像这样将标题添加为 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;
}
关于ios - UITableViewCell 滚动自定义 UITableView 标题标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34417449/