簡體   English   中英

UITableView節標頭放錯了位置

[英]UITableView section header missplaced

我的UITableView中出現了非常奇怪的錯誤。 我正在使用標准視圖和部分。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44.0f;
}

- (NSString*) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
switch (section)
{
    case kSectionProfile:
        return @"Profile";
        break;

    case kSectionContacts:
        return @"Contacts";
        break;

    case kSectionApps:
        return @"Apps";
        break;

    case kSectionSettings:
        return @"Settings";
        break;

    case kSectionCount:
        return nil;
        break;
}

return nil;
}

TableView來自XIB。

在此處輸入圖片說明

模擬器: 在此處輸入圖片說明

在此處輸入圖片說明

這是UITableView的頂部,該節永遠不會觸及可見區域的頂部,並且將在節標題周圍繪制單元格。 我不知道是什么原因導致了這個奇怪的問題。 似乎未正確計算UITableView的頂部。

更新:取消選中層次結構中VC對象上的情節提要/ XIB中的以下框。 在此處輸入圖片說明

從這里開始UITableView從iOS 7中的偏移量開始

舊答案:

使用- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section委托方法,看看是否有幫助。

例如

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20.0f;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM