[TableView] Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes. Make a symbolic breakpoint at UITableViewAlertForLayoutOutsideViewHierarchy to catch this in the debugger and see what caused this to occur, so you can avoid this action altogether if possible, or defer it until the table view has been added to a window. Table view: <FLTableView: 0x14384fe00; baseClass = UITableView; frame = (0 12; 390 741); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x280689c80>; layer = <CALayer: 0x280863b00>; contentOffset: {0, 0}; contentSize: {390, 769.33333333333326}; adjustedContentInset: {0, 0, 0, 0}; dataSource: <ReleaseSupplyVC: 0x14310dfc0>>
刷新UITableView的时候,出现了类似的警告,出现这个问题的原因是:要刷新的cell,当前没有出现在视图中,就已经刷新了。
比如我出现的问题是在setter方法里刷新的
#pragma mark - setter && getter
- (void)setClassifyModel:(ClassifyModel *)classifyModel {
_classifyModel = classifyModel;
self.model.productId = [classifyModel.classId integerValue];
self.model.classifyId = classifyModel.classifyId;
self.model.mdName = classifyModel.classifyName;
[self.tableView reloadRow:1 inSection:0 withRowAnimation:UITableViewRowAnimationNone];
}
但此时控制器的view都没有显示。所以报了类似警告。
修改的方法就是把刷新的时机调整到
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//刷新放在 set 方法里时机过早,会报错,调整到这里 ----》品类
[self.tableView reloadRow:1 inSection:0 withRowAnimation:UITableViewRowAnimationNone];
}
或者是
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}