2014-12-19 73 views
7

如何解决图像中显示的问题?UITableView节头插入缺失

tableview的section header缺少一个插入。

section header for the tableview is missing an inset.

+1

您是否试过去尺寸检查器并更改标头的高度? – 2014-12-19 08:09:04

+0

不,尝试过但它没有帮助。虽然谢谢! – stackOverFlew 2014-12-19 08:15:28

回答

15

你可能设置分隔符插图为0,无论是在代码或Interface Builder中(可以在属性检查器中找到:

Separator insets set to 0

这也导致了职称没有插图,默认值是左边的15和右边的0

+1

谢谢!我没有这样做在IB,但我打电话“”“如果([self.tableView respondsToSelector:@selector(separatorInset)] { [self.tableView setSeparatorInset:UIEdgeInsetsZero]; }”“” – stackOverFlew 2014-12-19 09:29:40

4

[你可以发布你的代码UITableViewDelegate? 在UITableView,没有API可以在部分标题中设置此插页,因此您可以返回tableView:viewForHeaderInSection:中的自定义UIView,然后设置所需的布局。

 
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 
    UIView *headerView = [UIView alloc] init]; 
    UILabel *headerLabel = [UILabel alloc] init]; 
    headerLabel.text = @"xxx"; 
    [headerLabel sizeToFit]; 
    headerLabel.frame = CGRectMake(20, 0, CGRectGetWidth(headerLabel.frame), CGRectGetHeight(headerLabel.frame)); 
    [headerView addSubview:headerLabel]; 
    headerView.frame = CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), CGRectGetHeight(headerLabel.frame)); 
    return headerView; 
}