我有 Thrift 服务器,我可以获取信息并将它们加载到我的 UITableView 中,首先我加载 10 行,每次滚动到最后我想再加载 10 行(带有信息)但它对我来说永远不起作用,
你能在这个实施中帮助我吗?
提前致谢!
这是我的 numberOfRowsInSection 方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _notes.count;
}
我的方法 scrollViewDidScroll
-(void)scrollViewDidScroll: (UIScrollView*)scrollView
{
float scrollViewHeight = scrollView.frame.size.height;
float scrollContentSizeHeight = scrollView.contentSize.height;
float scrollOffset = scrollView.contentOffset.y;
if (scrollOffset == 1)
{
[self.tableView setContentOffset:CGPointMake(0, 44)];
}
else if (scrollOffset + scrollViewHeight == scrollContentSizeHeight)
{
// I don't know what should I put here
NSLog(@"%@ we are at the end", _notes); //==> _notes is null
//we are at the end, it's in the log each time that scroll, is at the end
}
这是我连接到服务器的方式
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:YES];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
(unsigned long)NULL), ^(void) {
NSURL *url = [NSURL URLWithString:BASE_URL];
THTTPClient *transport = [[THTTPClient alloc] initWithURL:url];
TBinaryProtocol *protocol = [[TBinaryProtocol alloc]
initWithTransport:transport
strictRead:YES
strictWrite:YES];
server = [[thrift_Client alloc] initWithProtocol:protocol];
_notes = [server get_notes:10 offset:0 sort_by:0 search_for:result];
__weak NotesTable *weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf.notesTable reloadData];
});
});
[self.view setNeedsDisplay];
}