Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.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
标题部分的tableView视图从ios7中的第1部分开始_Ios_Iphone_Objective C_Uitableview_Ios7 - Fatal编程技术网

标题部分的tableView视图从ios7中的第1部分开始

标题部分的tableView视图从ios7中的第1部分开始,ios,iphone,objective-c,uitableview,ios7,Ios,Iphone,Objective C,Uitableview,Ios7,在这里,当我调试时,代码部分返回1,因此没有执行代码部分0。因此,我无法在我的表头视图中获取总体进度文本。在tableView:heightForHeaderInSection:的实现中是什么?如果您在那里为节0返回0,则我们的视图将调整为完全不可见。解决方案是使用您想要的高度实现heightForHeaderInSection - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)sec

在这里,当我调试时,代码部分返回1,因此没有执行代码部分0。因此,我无法在我的表头视图中获取总体进度文本。

在tableView:heightForHeaderInSection:的实现中是什么?如果您在那里为节0返回0,则我们的视图将调整为完全不可见。

解决方案是使用您想要的高度实现heightForHeaderInSection

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 

{

    NSString *sectionTitle = @"";

    if(section == 0)
        sectionTitle = @"Overall Progress";
    else
        sectionTitle = [[courses objectAtIndex:section-1] objectForKey:@"course-name"];

    // Create label with section title
    UILabel *label = [[[UILabel alloc] init] autorelease];

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        label.frame = CGRectMake(15, 10, 300, 30);
        label.font = [UIFont boldSystemFontOfSize:14];
    }
    else
    {
        label.frame = CGRectMake(50, 20, 600, 60);
        label.font = [UIFont boldSystemFontOfSize:19];

    }

    label.text = sectionTitle;
    label.backgroundColor = [UIColor clearColor];
    [label sizeToFit];
    // Create header view and add label as a subview
    UIView *view;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){

        view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
    }
    else{
        view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 640, 500)];
        view.backgroundColor = [UIColor clearColor];
    }

    [view addSubview:label];
    [view autorelease];
    return view;
}
从表视图:头部高度部分:

在iOS 5.0之前,对于tableView:ViewForHeaderInstruction:返回零视图的部分,表视图会自动将标题高度调整为0。在iOS 5.0及更高版本中,必须在此方法中返回每个节标题的实际高度

从tableView:ViewForHeaderIn部分:

返回的对象可以是UILabel或UIImageView对象,也可以是自定义视图。此方法仅在同时实现tableView:heightForHeaderInSection:时才能正常工作


请参见

尽管它在iOS 6及以下版本中运行良好,但您会遇到什么样的错误?我不会遇到任何错误。它好像不是从节0开始的,所以我的节0代码没有被执行…请发布其他委托方法。节0有多少行?-(CGFloat)tableView:(UITableView*)tableView heightforrowatinexpath:(nsindepath*)indepath{return 27.0;}
   - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    {
        return 44;
    }