【问题标题】:UITableView automatically drop down with paginationUITableView 自动下拉分页
【发布时间】:2021-12-05 05:00:36
【问题描述】:

我有一个关于 Objective-c 的大型遗留项目,并在我们开始将其转移到 swift 之前尝试实现新功能。 所以我现在正在聊天并像在电报中一样创建“搜索”。 从服务器获得 200status 后,我们在聊天中收到 41 条消息。我将用户屏幕设置在此消息的中间,并且需要在两侧实现分页。 我已经成功添加了这两个功能,需要解决最后一个问题:

当用户向上或向下滚动到另一条消息时,我已签入 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");
        }
    }

所以,问题是:

当我向上滚动时,我的 [_tableVIew contentOffset] 会自动计算(或者我找不到它发生的位置,但我已经使用 cmd+f 检查了所有项目)。 但是当用户向下滚动时,对于新消息,表格视图使用方法添加消息:

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

在这之后,我的 tableview 被放到了 [tableView offset] = 0(等于 indexPath.row = 0)。所以这会自动调用分页方法并再次将页面放到第一个元素。

我认为我需要在 [tableview reloadData] 之后设置新的 contentOffset。但我无法计算。 有人可以帮忙:如何计算从 tableView minY 到 tableView currentY 的偏移量?还是我做错了一切? 我想我在这个可怕的项目中找不到一些方法,但我希望你能帮助我解决这种情况。

in this picture 我需要计算从黑色方块底部到蓝色方块按钮的偏移量。因为在 [tableView reloadData] 之后黑色方块(即手机屏幕)立即下降到蓝屏底部并再次转动分页。而且它不断地重复..

非常感谢,伙计们!

【问题讨论】:

    标签: ios objective-c pagination tableview contentoffset


    【解决方案1】:

    我通过更改我在 google 中的搜索找到了答案:D 我花了 3 天时间。

    UIScrollView disable vertical bounce only at bottom

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-30
      • 1970-01-01
      • 2021-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多