viewWillLayoutSubviews

viewWillLayoutSubviews

在我的代码中,我正在无限调用viewWillLayoutSubviews方法。在viewWillLayoutSubviews中,我正在重新加载表,这会导致大量内存泄漏,并导致iPad 2屏幕冻结。

- (void)viewWillLayoutSubviews {
  [super viewWillLayoutSubviews];

  if ([APP_DELEGATE popOverIsOpened]) {

    [socalMedia dismissView];
    [self performSelectorInBackground:@selector(exiBack) withObject:nil];
  }
  [self.pTableView reloadData];
  if (([[UIApplication sharedApplication] statusBarOrientation] ==
       UIDeviceOrientationPortrait) ||
      ([[UIDevice currentDevice] orientation] ==
       UIDeviceOrientationPortraitUpsideDown)) {
    _pView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
    webView.frame = CGRectMake(0, 64, 768, 1024 - 64);
  } else {

    _pView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
    webView.frame = CGRectMake(0, 64, 1024, 768 - 64);
  }

  CGRect frm = self.navigationController.view.frame;
  frm.origin.y = 0;
  self.navigationController.view.frame = frm;

}


在什么情况下,viewWillLayoutSubviews方法调用?是自动呼叫还是方向改变时呼叫?

最佳答案

调整View大小(在此处将frm设置为self.navigationController.view.frame)并由其父级定位时,将调用viewWillLayoutSubviews方法。

关于ios - 无限期调用viewWillLayoutSubviews会导致屏幕卡住和内存警告,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32985333/

10-13 09:11