我有一个 UITableView,它是一个分组 TableView 。我正在尝试将图像添加为 TableView 的标题(并且仅适用于第一部分)。我遇到的问题是图像覆盖了表格 View 的第一部分。
代码如下:
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 80)];
NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.eventsforacausesf.com/uploads/8/7/3/0/8730216/3416277_orig.jpg"]];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, headerView.frame.size.width, headerView.frame.size.height)];
imageView.image = [UIImage imageWithData:imageData];
[headerView addSubview:imageView];
if (section == 0) {
return headerView;
}
return nil;
}
例如,在下图中,tableview 的第一部分隐藏在图像后面。我需要将该部分移到图片下方。
最佳答案
您使用该数据源方法设置的是 TableView 特定部分的 header ,但在我看来您想要的是设置 TableView 的 tableViewHeader
本身。将 TableView 的 tableViewHeader
属性设置为标题 View ,而不是将标题 View 作为节标题返回。然后您将获得标准的 iOS header 与内容布局。
关于ios - UITableView 的第一部分被 viewForHeaderInSection 隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15978830/