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 Written on October 10, 2020 Please enable JavaScript to view the comments powered by Disqus.