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 

希望这有助于添加按钮,并设置页脚到所需的大小。

相关问题