iOS 14适配之--UITableView

Posted 泉_哥

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS 14适配之--UITableView相关的知识,希望对你有一定的参考价值。

ios 14适配之–UITableView

概览

最近升级了Xcode12 ,编译完项目发现有个bug,就是UITableView里面的部分cell无法点击,通过Debug View Hierarchy 发现最上面有个UITableViewCellContentView类型的view。

如何修改

这个其实是写代码不规范造成的,正确的操作 在UITableViewCell自定义过程中

[self.contentView addSubview:self.bottomBoxView];

错误


[self addSubview:self.bottomBoxView];

因为代码中有大量的代码,如何快速的修复?


@interface UIView (FixiOS14Bug)
@end

@implementation UIView (FixiOS14Bug)
+ (void)load 
    Method addSubview = class_getInstanceMethod(self, @selector(addSubview:));
    Method customAddSubview = class_getInstanceMethod(self, @selector(customAddSubview:));
    method_exchangeImplementations(addSubview, customAddSubview);


-(void)customAddSubview:(UIView*)view

    [self customAddSubview:view];
    if ([self isKindOfClass:[UITableViewCell class]]  && ![NSStringFromClass([view class]) containsString:@"UITableViewCellContentView"]) 
       
        UITableViewCell* cell =  (UITableViewCell*)self;
        cell.contentView.hidden = [cell.contentView subviews].count == 0;
    

@end

以上是关于iOS 14适配之--UITableView的主要内容,如果未能解决你的问题,请参考以下文章