ios - UITableView 的第一部分被 viewForHeaderInSection 隐藏

标签 ios objective-c ios5 ios6

我有一个 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 的第一部分隐藏在图像后面。我需要将该部分移到图片下方。

Description

最佳答案

您使用该数据源方法设置的是 TableView 特定部分的 header ,但在我看来您想要的是设置 TableView 的 tableViewHeader本身。将 TableView 的 tableViewHeader 属性设置为标题 View ,而不是将标题 View 作为节标题返回。然后您将获得标准的 iOS header 与内容布局。

关于ios - UITableView 的第一部分被 viewForHeaderInSection 隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15978830/

相关文章:

ios rectOfInterest AVCaptureMetadataOutput 忽略

ios - 在没有UINavigationController的情况下向navigationItem添加backBarButtonItem?

javascript - javascript 函数 srcElement.nodeName 在 iOS5 中给出了错误的输出

ios - 本地通知覆盖iOS 9中的远程通知(可行通知)设置?

ios - UIImagePickerController 强制其他 View 中的图像为全尺寸

iphone - 访问可以更新的固定应用程序资源的正确方法是什么?

iphone - 无法从委托(delegate)调用 Controller 方法

ios - 在 Swift 中将叠加效果从 psd 转换为 UIImage

ios - Firebase iOS .queryOrderedByChild 和 .queryEqualTo 不工作

objective-c - LLDB 等同于 Xcode4.1 中 GDB 中的 `po`?