iOS 14适配之--UITableView

iOS 14适配之–UITableView

概览

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

ios14bug

如何修改

这个其实是写代码不规范造成的,正确的操作 在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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值