ios – 自定义标题重叠组中的单元格

我有点卡住尝试创建自定义ios表头.我的标题是30px高,我使用此代码来创建它们:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
    if (sectionTitle == nil) {
        return nil;
    }

    // Create label with section title
    UILabel *label = [[UILabel alloc] init] ;
    label.frame = CGRectMake(0,140,30);
    label.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"header_gradient.png"]];
    label.textColor = [UIColor whiteColor];
    label.shadowColor = [UIColor whiteColor];
    label.shadowOffset = CGSizeMake(0.0,1.0);
    label.font = [UIFont boldSystemFontOfSize:12];
    label.text = sectionTitle;

    // Create header view and add label as a subview
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,30)];
    [view addSubview:label];

    return view;
}

- (CGFloat)tableView:(UITableView *)tableViewheightForHeaderInSection:(NSInteger)section {
    return 30;
}

它几乎可以工作,但我的标题似乎与它们下面的单元格/标题相符:

有人能指出我在清理标题的正确方向吗?

提前致谢

解决方法

你错过了[空间]:

你有:

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

它应该是:

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

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...