0

私は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];
}
4

3 に答える 3

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...        
    }
    } 
}
于 2013-10-25T04:54:35.210 に答える