0
votes

I've decision customizing the tableView in moreNavigationController, I tested it and work great and no problem but why am I getting error:

2020-05-31 17:16:23.395903-0600 Code Notes[1472:329155] [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: <_UIMoreListTableView: 0x13a866e00; frame = (0 44; 414 852); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = ; layer = ; contentOffset: {0, 0}; contentSize: {414, 176}; adjustedContentInset: {0, 0, 0, 0}; dataSource: >

I am not sure how can I resolve it, how can I solve it? Here my codes:

if let moretableview = moreNavigationController.topViewController?.view as? UITableView {
   moretableview.backgroundColor = UIColor(named: "mainbackground")
   for cell in moretableview.visibleCells {
      cell.backgroundColor = UIColor.clear
   }
}
1

1 Answers

1
votes

Timing is everything. By saying

moreNavigationController.topViewController?.view

at the time you are saying it, you are forcing the table view controller to get its view prematurely. You are then modifying the view, which is a table view, when it has not yet entered the interface. This causes the runtime to complain.