2018-12-28 在快速滚动tableView的时候,取得cell为nil

项目有个需求,在快速滚动tableView时候,将即将结束滚动的cell赋值保存。

  • (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset方法中能预判断Offset。
    调试慢速滚动能取到cell,快速连续滑动时候,cell==nil
    然后加了个延迟0.1秒,完美解决。
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
    CGPoint rect = CGPointMake(targetContentOffset->x, targetContentOffset->y);
    NSInteger index = rect.y / self.view.height;
    if (_beginDragging && _liveInfoIndex != index) {
        if (index > _liveInfoIndex) {
            _dragDirection = DragDirection_Down;
        }else{
            _dragDirection = DragDirection_Up;
        }

        _liveInfoIndex = index;
        //先暂停上一个播放器
        if (_currentPlayer) {
            [_currentPlayer seek:0];
            [_currentPlayer removeVideoWidget];
            [_currentCell.logicView.playProgress setValue:0];
        }
        _videoPause = NO;
        //延迟0.1秒,防止取得的cell未初始化为nil
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            _currentCell = [_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:_liveInfoIndex inSection:0]];
            [_currentCell.logicView.playProgress setValue:0];
            [self resumePlayer];
            [self requestPlayNum];
        });
        _beginDragging = NO;
    }else if (_beginDragging && _liveInfoIndex == index){
        if (_currentPlayer) {
            [_currentPlayer setupVideoWidget:_currentCell.videoParentView insertIndex:0];
            if(_videoPause == NO){
                [_currentPlayer resume];
            };
        }
    }
}

你可能感兴趣的:(2018-12-28 在快速滚动tableView的时候,取得cell为nil)