- (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;
}
在此代码部分中,当我调试时返回 1,因此第 0 部分代码不会被执行。因此,我无法在表头视图中获得整体进度文本。