0

나는 Thrift 서버를 가지고 정보를 얻을 수 있고 UITableView에로드 할 수 있습니다. 처음에는 10 행을로드하고 10 개를로드 할 때마다 끝까지 스크롤 한 후로드합니다. 행 (정보)하지만 사전에,스크롤 후 UITableView에 더 많은 데이터를로드하는 방법

당신이이 구현에서 저를 도와주세요 것, 나를 위해

덕분에 일을 결코!

여기 내 방법 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]; 
} 

답변

2

당신은 당신의 요청을 넣어야에 연결하는 방법입니다

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 

return _notes.count; 
} 

내 numberOfRowsInSection 방법

입니다. viewdidappear ..에서 실행중인 하나는 viewdid에서 제거하십시오. 그런 다음 viewdidappear에서이 메서드를 호출하고이 곳에서 당신이 didscroll이의 구현 대신 로그를 넣고 하나는 ... 더

- (void)scrollViewDidScroll: (UIScrollView *)scroll { 
    NSInteger currentOffset = scroll.contentOffset.y; 
    NSInteger maximumOffset = scroll.contentSize.height - scroll.frame.size.height; 

    // Change 10.0 to adjust the distance from bottom 
    if (maximumOffset - currentOffset <= 10.0) { 
      [self methodThatAddsDataAndReloadsTableView]; 
    } 
} 
2

안녕이이 시도 나를 위해 완벽하게 작동이 사용입니다

- (void)scrollViewDidScroll:(UIScrollView *)aScrollView 
{ 
    CGPoint offset = aScrollView.contentOffset; 
    CGRect bounds = aScrollView.bounds; 
    CGSize size = aScrollView.contentSize; 
    UIEdgeInsets inset = aScrollView.contentInset; 
    float y = offset.y + bounds.size.height - inset.bottom; 
    float h = size.height; 
    float reload_distance = 10; 
    if(y > h + reload_distance) 
    { 

    //Put your load more data method here...   
    } 
    } 
} 
3

SVPullToRefresh을 사용하면 멋진 캡슐화를 제공합니다. 라이브러리를 추가하고 UITableView를

[tableView addInfiniteScrollingWithActionHandler:^{ 
    // prepend data to dataSource, insert cells at top of table view 
    // call [tableView.pullToRefreshView stopAnimating] when done 
}]; 
과 함께 등록하십시오.
관련 문제