32位iPad:
64位iPad:
这是代码:
- (float) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 40.0; } - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,tableView.frame.size.width,40)]; [headerView setBackgroundColor:[UIColor grayColor]]; UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,113,headerView.frame.size.height)]; nameLabel.font = [UIFont systemFontOfSize:14]; nameLabel.numberOfLines = 0; nameLabel.textAlignment = NSTextAlignmentCenter; nameLabel.text = @"Name"; [headerView addSubview:nameLabel]; nameLabel = [[UILabel alloc] init]; nameLabel.numberOfLines = 0; nameLabel.font = [UIFont systemFontOfSize:14]; nameLabel.frame = CGRectMake(175,50,headerView.frame.size.height); nameLabel.text = @"Risk Level"; [headerView addSubview:nameLabel]; nameLabel = [[UILabel alloc] init]; nameLabel.numberOfLines = 0; nameLabel.font = [UIFont systemFontOfSize:14]; nameLabel.frame = CGRectMake(220,headerView.frame.size.height); nameLabel.text = @"Code"; [headerView addSubview:nameLabel]; nameLabel = [[UILabel alloc] init]; nameLabel.numberOfLines = 0; nameLabel.font = [UIFont systemFontOfSize:14]; nameLabel.frame = CGRectMake(280,60,headerView.frame.size.height); nameLabel.text = @"Currency"; [headerView addSubview:nameLabel]; nameLabel = [[UILabel alloc] init]; nameLabel.numberOfLines = 0; nameLabel.font = [UIFont systemFontOfSize:14]; nameLabel.frame = CGRectMake(420,100,headerView.frame.size.height); nameLabel.text = @"Issuer"; [headerView addSubview:nameLabel]; return headerView; }
解决方法
找到了解决方案.
不得不使用CGFloat而不是float作为heightForHeaderAtSection的返回类型: