概述
在获取复用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;
}
网友评论