2011-05-08 67 views
5

我剛剛實現了一個加載更多按鈕到我的tableView的頁腳,但頁腳始終與表滾動。我的tableView的風格是UITableViewStylePlain。TableView頁腳滾動表

請你能告訴我我哪裏出錯了。

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { 
    UIView *footerView = nil; 
    if(footerView == nil) { 
     footerView = [[[UIView alloc] init] autorelease]; 
     footerView.backgroundColor = [UIColor clearColor]; 
     UIButton *button = [[UIButton alloc] init];  
     button.layer.cornerRadius = 7; 
     [button setFrame:CGRectMake(10, 3, 300, 44)]; 
     [button setTitle:@"Load 20 more" forState:UIControlStateNormal]; 
     [button.titleLabel setFont:[UIFont boldSystemFontOfSize:20]]; 
     [button setBackgroundColor:[UIColor whiteColor]]; 
     [button.titleLabel setTextColor:[UIColor blackColor]]; 
     [button addTarget:self action:@selector(load20More) forControlEvents:UIControlEventTouchUpInside]; 
     [footerView addSubview:button]; 
     [button release]; 
    } 
    if ([songInfo count] > 20 && count < 100) { 
     return footerView; 
    } 
    else 
     return nil; 
} 
+0

當您按加載更多時,您想要發生什麼? – Cyprian 2011-05-08 18:50:06

+0

加載更多工作完美,並且不會影響tableView的頁腳與表格的滾動。 – 2011-05-08 19:16:33

回答

24

首先,tableView:viewForFooterInSection不爲表定義頁腳,它定義了在表中的部分頁腳。您可以在一個表格中包含多個分節頁腳。在您的表只有一個部分的情況下,使用此方法在功能上等同於添加表格頁腳,但它不是表格的頁腳。如果這是你想要的,使用實際的頁腳是更好的做法,這可以通過簡單地將視圖分配給UITableViewtableFooterView屬性來實現。

但是,頁腳(頁腳和頁腳)都是爲了與您的桌子一起滾動而構建的。如果您想要實現一個粘在屏幕底部並且不隨桌子滾動的「頁腳」,最好的辦法就是調整您的UITableView的大小以便爲「頁腳」騰出空間,並添加一個新的視圖以坐在你剛剛清理過的地方。這樣,它會堅持到位,並且表格中的可滾動區域不會與「頁腳」重疊。

+0

如何在使用故事板時調整UITableView的大小?你是指在代碼中調整大小,還是在xib或故事板編輯器中調整大小? – Teevus 2013-08-27 03:22:11

+0

我指的是在代碼中調整大小。我不使用xib或故事板,你必須問別人。 – thefugal 2013-08-27 23:45:26

+0

這是絕對正確的 – Jesse 2013-10-18 14:23:51