0

I've got a huge legacy project on objective-c and trying to implement new features before we starting to move it to swift. So I'm working on chat right now and creating "Search" like in telegram. After we got 200status from server we got 41 message in chat. Im set user screen to the middle of this messages, and need to implement pagination in both sides. I've successfully added both features, and need to resolve last problem:

When user scroll UP or down to the another messages, I've got check in scrollViewDidScroll:

    CGPoint offset = scrollView.contentOffset;
    CGSize  size = scrollView.contentSize;
    CGFloat height = _tableView.frame.size.height;

        if (offset.y > size.height - height) {
        if((isLoadingMessages == NO) && (loadedMessagesUp % MAX_LOADING_MESS == 0)){
            _isFromSearch = false;
            NSInteger create = [[[_messagesArray lastObject] objectForKey:@"create"] integerValue];
            _dateForPagination = create;
            scrollDirectionDown = false;
            [self loadMessages];
            NSLog(@"pagination up");
        }
    }
    if(offset.y < 10) {

        if((isLoadingMessages == NO) && (loadedMessagesDown % MAX_LOADING_MESS == 0)){
            _isFromSearch = false;
            NSInteger create = [[[_messagesArray firstObject] objectForKey:@"create"] integerValue];
            _dateForPagination = create;
            scrollDirectionDown = true;
            [self loadMessages];
            NSLog(@"pagination down");
        }
    }

So, the question is:

When I've scrolledUP, my [_tableVIew contentOffset] calculated automatically (or I can't find where it happened, but I've check all project with cmd+f). But when user scrollDOWN, to the new messages, table view added messages with method:

if (scrollDirectionDown) {
_paginationMessagesArray = [[[_paginationMessagesArray reverseObjectEnumerator]allObjects]mutableCopy];
[_paginationMessagesArray addObjectsFromArray: _messagesArray];
_messagesArray = _paginationMessagesArray;
}

And after this dropped my tableview to the [tableView offset] = 0 (equal indexPath.row = 0). So this automatically calls method with pagination and again dropped page to first element.

I think that I need to set new contentOffset after [tableview reloadData]. But I can't calculate it. Can somebody help: how to calculate offset from to tableView minY to the tableView currentY ? Or I do everything wrong? I suppose that I can't find some method in this terrible project, but I hope you can help to me with this situation.

in this picture I need to calculate offset from bottom of black square to the button of blue square. Because after [tableView reloadData] black square (which is screen of the phone) immediately drops to the bottom of blue Screen and turning pagination again. And it repeating and repeating..

THanks a lot, mates!

Sergey Udalov
  • 75
  • 1
  • 7

1 Answers1

0

I found answer by changing my search in google :D 3 days I've spent on this.

UIScrollView disable vertical bounce only at bottom

Sergey Udalov
  • 75
  • 1
  • 7