美文网首页iOS 14 踩坑
iOS 14 踩坑-UITableView

iOS 14 踩坑-UITableView

作者: 泉_哥 | 来源:发表于2020-10-12 16:32 被阅读0次

    iOS 14适配之--UITableView

    概览

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

    ios14tableview.png

    如何修改

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

        本文链接:https://www.haomeiwen.com/subject/dkcppktx.html