如果没有提供我的所有代码示例,我会快速完成。
你们其中一个人有没有想过只在第一次出现时才调用viewWillAppear?
我的所有观点都存在这个问题。
例如:当我的应用程序启动时,我会进入StartView这是一个主菜单。 (viewWillAppear被调用)然后我按下一个按钮,它将显示一个导航控制器(viewWillAppear被调用)。然后我回到主菜单(它没有被调用),然后我再次按下相同的导航控制器,它不会被调用。
如果有人能把我指向某个地方会很棒,我已经两天就一直在寻找这个......
此外,如果您需要更多代码示例,我可以给您一些。
进一步阅读:
这就是我调用导航控制器的方式:
PremierSoinsAppDelegate *AppDelegate = (PremierSoinsAppDelegate *)[[UIApplication sharedApplication] delegate];
UIView *newView = [AppDelegate.navigationController view];
[newView setFrame:CGRectMake(320.0f, 0.0f, 320.0f, 480.0f)];
[UIView beginAnimations:@"RootViewController" context:nil];
[UIView setAnimationDuration:0.3];
newView setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
UIView commitAnimations];
[AppDelegate.window addSubview:newView];
[AppDelegate.window makeKeyAndVisible];
这就是我回放菜单的方式:
PremierSoinsAppDelegate *AppDelegate = (PremierSoinsAppDelegate *)[[UIApplication sharedApplication] delegate];
UIView *newView = [AppDelegate.startViewController view];
newView setFrame:CGRectMake(-320.0f, 0.0f, 320.0f, 480.0f)];
UIView beginAnimations:@"StartViewController" context:nil];
UIView setAnimationDuration:0.3];
newView setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
[UIView commitAnimations];
[AppDelegate.window addSubview:newView];
[AppDelegate.window makeKeyAndVisible];
非常感谢。
答案 0 :(得分:1)
viewWill / DidAppear:仅在使用UINavigationController或UITabBarController(或实际上任何系统提供的viewControlller管理类)来操作视图时才会被调用。如果您手动执行此操作(就像您在第二个代码段中所做的那样,这些消息将不会被发送。
答案 1 :(得分:1)
您可以在Nav Controller中实现UINavigationControllerDelegate,以向下传播viewWillAppear:消息。您可以实现如下消息:
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if ([viewController respondsToSelector:@selector(viewDidAppear:)]) {
[viewController viewDidAppear:animated];
}
}
请注意,这是viewDidAppear而不是ViewWillAppear版本,但它们基本相同。
但是,您应该注意,您需要执行此操作的事实可能表明您的控制器/视图代码中存在其他错误,并且您可能希望重新提供问题,从而为我们提供更多上下文来回答它。特别是,我假设在你给我们的代码之外的某个地方,你按照通常的方式推导和弹出视图控制器。