Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 自定义标题与组中的单元格重叠_Ios_Objective C_Uitableview_Ios5 - Fatal编程技术网

Ios 自定义标题与组中的单元格重叠

Ios 自定义标题与组中的单元格重叠,ios,objective-c,uitableview,ios5,Ios,Objective C,Uitableview,Ios5,我在尝试创建自定义ios表头时有点卡住了。我的头高30像素,我正在使用以下代码创建它们: - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section]; if (sectionTitle == n

我在尝试创建自定义ios表头时有点卡住了。我的头高30像素,我正在使用以下代码创建它们:

- (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, 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, 0, 140, 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 {

它实际上应该是
-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
正确。正确的声明如下(来自文档):-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section-如果您密切关注,tableView和heightForHeaderInSection之间缺少[space]。。。第一次完全没有注意到这一点,因此我认为骆驼案已经结束了。我已经更新了答案。谢谢你的接球!谢谢你的帮助。。。我要发疯了,想弄明白为什么那不管用!