Xcode12正式发布6天后(20200922)打包后问题总结一:Xcode12下UITableViewCell内容不显示问题
- 作者: 听说段子很搞笑
- 来源: 51数据库
- 2021-07-30
?
?
直接看到的现象是UITableViewCell为浅灰色
?
页面结构查看是UITableViewCell的contentView在最上面,自己添加的控件被它盖在下面了。
?
问题原因是我们添加控件的时候没有添加到contentView上,而是直接[self addSubview:xxx].
?
解决办法:将上面代码改为[self.contentView addSubview:XXX]
?
?
如果特别多,短时间见效,则交换UIView的addSubview方法,一次全部解决
UIView+YYY.h
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIView (YYY)
@end
NS_ASSUME_NONNULL_END
UIView+YYY.m
#import "UIView+YYY.h"
#import <objc/runtime.h>
@implementation UIView (YYY)
+ (void)load{
//适配xcode12tablecell问题
Method originalMethod = class_getInstanceMethod([self class], @selector(addSubview:));
Method swizzledMethod = class_getInstanceMethod([self class], @selector(addSubviewS:));
method_exchangeImplementations(originalMethod, swizzledMethod);
}
- (void)addSubviewS:(UIView *)view{
if ([self isKindOfClass:[UITableViewCell class]]) {
//cell自己添加contentView不可以更改
if([view isKindOfClass:[NSClassFromString(@"UITableViewCellContentView") class]]){
[self addSubviewS:view];
}else{
//如果是cell自己添加view则改用它的contentView添加
UITableViewCell *cell = self;
[cell.contentView addSubview:view];
}
}else{
[self addSubviewS:view];
}
}
@end
?
这样90%以上的问题都会解决,可能还会有cell不显示,问题可能出在removeAllSubviews
如果以前这么写的
while (self.subviews.count) {
UIView* child = self.subviews.lastObject;
[child removeFromSuperview];
}
会把cell自己的contentView也remove掉,代码要改为
while (self.contentView.subviews.count) {
UIView* child = self.contentView.subviews.lastObject;
[child removeFromSuperview];
}
?
?
?
?
?
?
推荐阅读
热点文章
android中Bitmap用法(显示,保存,缩放,旋转)实例分析
12
android 仿微信聊天气泡效果实现思路
1
Android的尺度,drawable-xxxxxxx
2
Codeforces Round #656 (Div. 3) (C、D题)
1
Android之handler异步消息处理机制解析
6
GridView中图片显示出现上下间距过大,左右图片显示类似瀑布流的问题
0
AsyncTask的简单使用
5
两个简单Fragment之间的通信(三种方式)
18
uboot修改设置boot参数命令
41
android中实现从相册中一次性获取多张图片与拍照,并将选中的图片显示出来
2