2014-12-19 154 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; 
}