2014-03-12 42 views
4

我遇到一個奇怪的行爲UITableView。我用UITableView設置了一個UIViewControllerUITableView包含tableHeaderView,tableFooterView,部分頁腳視圖以及具有動態高度的幾個UITableViewCelltableFooterView在表格底部沒有正確對齊

問題是tableFooterView出現在表格中間某處(懸停在單元格上),而不是在表格內容的底部對齊。顯然,表的contentSize屬性也返回不正確的內容大小(具體是高度)。

但是,自定義部分頁腳視圖出現在正確的位置(並且低於實際的tableFooterView - 正在表中間盤旋)。

任何想法發生了什麼?

注意:我的自定義表視圖(使用自動佈局動態高度處理)顯示「模糊佈局:2視圖垂直不明確。」警告,但它在運行時正確調整大小。

表的設置是相當簡單:

// Set table header/footer view 
self.myTableView.tableHeaderView = self.myTableHeaderView; 
self.mainTableView.tableFooterView = self.myTableFooterView; 

// Table delegate methods 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return [self heightForCellAtIndexPath:indexPath]; 
} 

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return [MyCustomCell defaultHeight]; 
} 

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { 

    if (section == 0) { 
     return self.mySectionFooterView; 
    } 

    return [UIView new]; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { 

    if (section == 0) { 
     return [self heightForSectionFooterView]; 
    } 

    return 0.01f; 
} 

回答

2

我結束了使用一個額外的部分只有頁眉和頁腳(且行),以獲得理想的效果。也許自動佈局行事怪異。我仍然看到「不明確的佈局:2個視圖是垂直模糊的」,但UI看起來不錯。

+0

的tableFooterView對齊問題仍然在iOS 8.1中發生。您的解決方案工作...使用沒有行的節標題。好哇! – RyJ

0

嘗試設置footerView.autoresizingMask = .flexibleWidth

示例代碼:

let footerView = Bundle.main.loadNibNamed(String(describing: MyFooterView.self), owner: nil, options: nil)?.first as! MyFooterView 
footerView.frame = CGRect(origin: .zero, size: CGSize(width: view.bounds.width, height: 80)) 
footerView.autoresizingMask = .flexibleWidth 
tableView.tableFooterView = footerView