上拉加载更早时候的数据的开发思路

1. tableFootView上加一个button,点击后加载更早时候的数据。

2. 往上拖动一定的高度时候,自动加载更早时候的数据。

3. xib制作一个上拉加载的自定义控件,Xcode5不提供自定义view的xib勾选,只有cell可以。

4. 320*35点坐标,label填充整个view,正在加载更多微博,加一个刷新控件。+(instancetype)footer;

5. 控制器集成上拉刷新控件。

开发代码:

+ (instancetype)footer

{

return [[[NSBundle mainBundle] loadNibNamed:@"HWLoadMoreFooter" owner:nil options:nil] lastObject];

}

/**

*  集成上拉刷新控件

*/

- (void)setupUpRefresh

{

HWLoadMoreFooter *footer = [HWLoadMoreFooter footer];

footer.hidden = YES;

self.tableView.tableFooterView = footer;

}

拖动到一定程度加载更早时候的数据的开发代码:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

CGFloat offsetY = scrollView.contentOffset.y;

// 如果tableView还没有数据,就直接返回

if (self.statuses.count == 0) return;

//    if ([self.tableView numberOfRowsInSection:0] == 0) return;

// 当最后一个cell完全显示在眼前时,contentOffset的y值

CGFloat judgeOffsetY = scrollView.contentSize.height + scrollView.contentInset.bottom - scrollView.height - self.tableView.tableFooterView.height;

if (offsetY >= judgeOffsetY) { // 最后一个cell完全进入视野范围内

// 显示footer

self.tableView.tableFooterView.hidden = NO;

// 加载更多的微博数据

HWLog(@"加载更多的微博数据");

}

/*

contentInset:除具体内容以外的边框尺寸

contentSize: 里面的具体内容(header、cell、footer),除掉contentInset以外的尺寸

contentOffset:

1.它可以用来判断scrollView滚动到什么位置

2.指scrollView的内容超出了scrollView顶部的距离(除掉contentInset以外的尺寸)

*/

}

你可能感兴趣的:(上拉加载更早时候的数据的开发思路)