UITableViewAlertForLayoutOutsideViewHierarchy警告
Xcode中的console打印以下信息:
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: <UITableView: 0x7f9b55915e00; frame = (0 0; 414 813); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x600002b66c10>; layer = <CALayer: 0x600002572700>; contentOffset: {0, 0}; contentSize: {414, 596}; adjustedContentInset: {0, 0, 0, 0}; dataSource: <YMMinePageController: 0x7f9b54c173d0>>
经过排查,发现为以下代码导致的:
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:YES animated:animated]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.navigationController setNavigationBarHidden:NO animated:animated]; } - (void)generateSubviews { _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; }
视图层级结构为:tabBarController -> navigationController -> viewController -> self.view -> tableView,且均为第一个子/根控制器或子视图
将导航栏在当前界面隐藏,tableview占整个界面,第一次展示该界面,再切换tabBar回来后,打印最上面的警告信息,具体内部原因没有搞清楚
通过尝试,将_tableView.autoresizingMask属性删除,改为固定的rect,警告信息没有了,如下:
CGRect rect = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - TABBAR_HEIGHT); _tableView = [[UITableView alloc] initWithFrame:rect style:UITableViewStylePlain];

浙公网安备 33010602011771号