2016-03-31 30 views
0

我有一個UITableView有時是空的,我有一個頁腳UITableView。即使在表格視圖中沒有內容時,我想要的是始終顯示頁腳。這可能嗎?或者是更好地添加一個額外的單元格到UITableView並將其用作頁腳?當空的時顯示UITableView頁腳

寧願將其作爲頁腳單獨保存,而不是將其作爲單元格添加到UITableView的末尾。

任何幫助表示讚賞。

回答

0

您可以使用這樣的事情時,有沒有行

UIView* footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)]; 
    [footerView setBackgroundColor:[UIColor clearColor]]; 
    self.tableView.tableFooterView = footerView; 
    [self.tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)]; 
    [self.tableView setContentInset:(UIEdgeInsetsMake(0, 0, -350, 0))]; 
+0

我認爲這太hackey,不喜歡編輯內容插入的想法 –

+0

它不會產生任何問題 –

0

確定的第一件事是,當你說:「是的UITableView有時是空的」。所以如果你的表是空的,你在其中添加一個頁腳視圖。像下面一樣

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
{ 
    UIView* myFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 50)]; 
    [myFooterView setBackgroundColor:[UIColor blueColor]]; 
    return myFooterView; 
} 

您的頁腳視圖將顯示在tableview的頂部,因爲tableview.something中沒有任何行,如下圖所示。紅色是TableView顏色,藍色是頁腳視圖顏色。

enter image description here

當你的表是不是空的頁腳視圖會像

enter image description here

所以我建議你添加和低於該視圖表視圖,顯示內容多視圖。希望這會消除你的疑惑。