如何确保viewWillLayoutSubviews / All View Calls已经完成?

时间:2014-10-27 21:47:41

标签: ios uibutton viewwillappear

我有以下情况,我想在Autolayout中设置按钮后隐藏它。

基本上,这个方法称为- (void) hideSomeButton。我将此方法称为:

BlahViewController *bVC = [[UIStoryboard storyboardWithName:"Blah"] instantiateInitialViewController];
[self.navigationController pushViewController:bVC animated:YES];
[bVC hideSomeButton];

我假设这是方法调用的内容:

1. init Method
2. viewDidLoad
3. viewWillAppear
4. viewWillLayoutSubviews (This has an explicit call making someButton.hidden = NO)
5. viewDidLayoutSubviews
6. hideSomeButton (This has an explicit call making someButton.hidden = NO)

但是,`viewWillLayoutSubviews'被调用两次。因此,会发生什么:

1. viewWillLayoutSubviews - Button Shown
2. hideSomeButton - Button Hidden
3. viewWillLayoutSubviews - Button Shown

BOOM!没有隐藏按钮!请帮忙。

1 个答案:

答案 0 :(得分:0)

在调用[super viewWillLayoutSubviews]而不是在bVC上调用它之后,为什么不从BlahViewController里面的viewWillLayoutSubviews调用hideSomeButton?