2012-06-24 75 views
2

我想在UITableview的末尾添加一個加載更多按鈕。它與Instagram中的load-more按鈕具有相同的功能。這是圖片。如何在tableview底部添加加載更多按鈕?

pic

所以我的問題是如何將其在UITableview末尾添加?由於tableview是可滾動的,我不知道如何給按鈕一個動態的位置。

在此先感謝。

回答

0

每個UITableView都有一個footerView屬性。只要讓您的自定義footerView並設置屬性

@property(nonatomic, retain) UIView *tableFooterView 
7

創建一個空的UIView:UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 70)]; 創建按鈕:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button setTitle:@"Load More" forState:UIControlStateNormal]; 
[button addTarget:self action:@selector(buttonLoadMoreTouched) forControlEvents:UIControlEventTouchUpInside]; 
[button sizeToFit]; 

添加你按鈕的視圖的子視圖從1

[v addSubview:button]; 

將您的表的tableFooterView屬性設置爲從1開始的視圖。

self.myTableView.tableFooterView = v; 
+0

這是最好的答案。謝謝。 – zhyr28

+0

優秀的答案幫助我很多。非常感謝! – Mohit

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

你可以在上面的方法在下面的一個

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

希望這有助於添加按鈕,並設置頁腳到所需的大小。

相關問題