3D Touch PeeK And Pop导致TableView滑动卡顿问题

概述

在获取复用Cell方法中注册3D Touch Peek And Pop,导致滑动越来越卡顿。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    BaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
    if (@available(iOS 9.0, *)) {
        if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
            [self registerForPreviewingWithDelegate:self sourceView:cell];
        }
    }
    return cell;
}

解决方案

在复用Cell中添加一个是否已注册3D Touch Peek And Pop的属性register3DTouch标识,如已注册就不重复注册。

@interface BaseTableViewCell : UITableViewCell
@property (nonatomic,getter = isRegister3DTouch) BOOL register3DTouch; //cell是否注册3D Touch标识
- (void)registerPreviewingWithController:(UIViewController<UIViewControllerPreviewingDelegate> *)controller;
@end
    
@implementation BaseTableViewCell

- (void)registerPreviewingWithController:(UIViewController<UIViewControllerPreviewingDelegate> *)controller
{
    if (@available(iOS 9.0, *)) {
        if (controller.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable && !self.isRegister3DTouch) {
            [controller registerForPreviewingWithDelegate:controller sourceView:self];
            self.register3DTouch = YES;
        }
    }
}

@en

获取复用Cell中替换注册的API

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    BaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
    if (@available(iOS 9.0, *)) {
        if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
            [cell registerPreviewingWithController:self];
        }
    }
    return cell;
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容