本文介绍了tableView.tableHeaderView正在设置但未绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我设置tableHeaderView时,我都不会在Simulator中看到它.如果我将其添加为子视图,则最终将其绘制在节标题下.知道我在这里缺少什么吗?

whenever I set my tableHeaderView I'm not seeing it in the Simulator.If I add it as a subview, it ends up getting drawn underneath the section header. Any idea what I'm missing here?

我确实有XIB文件.我没有看到IB中的任何属性会影响headerViews.

I do have a XIB file. I didn't see any properties in IB to affect headerViews though.

- (void)viewDidLoad {   
[super viewDidLoad];
MyTitleView *titleView = [[MyTitleView alloc] initWithFrame:CGRectMake(60,0,260,40)];
titleView.label.text = @"My Title";
self.navigationItem.titleView = titleView;
[titleView release];

StandardTableHeaderView *headerView = [[StandardTableHeaderView alloc] initWithFrame:CGRectMake(0,0,320,44)];
self.tableView.tableHeaderView = headerView;
//  [self.view addSubview:self.tableView.tableHeaderView];
//  [headerView release];


NSLog(@"Header: %@",self.tableView.tableHeaderView); //Logs ] Header:     <StandardTableHeaderView: 0x5a508b0; frame = (0 0; 320 44); layer = <CALayer: 0x5a51130>>

StandardTableHeaderView.m初始化方法:

StandardTableHeaderView.m init method:

- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
    self.backgroundColor = [UIColor redColor];
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(frame.origin.x,0,frame.size.width,frame.size.height)];
    self.label.backgroundColor = [UIColor clearColor];
    self.label.textColor = [UIColor whiteColor];
    self.label.font = [UIFont fontWithName:@"Helvetica" size:16];
    [self addSubview:self.label];
}
return self;
}

推荐答案

首先,您的代码看起来不错.

First of all your code looks fine.

2个可能的问题:

  • self.tableView未设置
  • tableHeaderViewviewDidLoad之后被覆盖
  • self.tableView is not set
  • tableHeaderView is overridden after viewDidLoad

这篇关于tableView.tableHeaderView正在设置但未绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 20:17