gpt4 book ai didi

iphone - popviewcontroller 没有调用 viewWillappear

转载 作者:太空狗 更新时间:2023-10-30 03:40:50 30 4
gpt4 key购买 nike

我正在使用以下代码在用户单击按钮时显示上一个 View

[self.navigationController popViewControllerAnimated:YES];

在之前的 View 中,我覆盖了 viewWillAppear 以初始化一些东西。但是,似乎没有调用 viewWillAppear。我将 NSLog 放在 viewDidload、viewWillAppear、viewDidAppear 中,并且只调用 viewDidAppear。这是正常行为吗?如果是,我应该覆盖什么事件以便我可以进行初始化?谢谢。

根据要求-viewWillAppear 用于上一个 View

- (void)viewWillAppear:(BOOL)animated{

NSLog(@"ViewWillAppear");
//[[GameStore defaultStore] resetGame];
[self setHangmanImage];

NSLog([[[GameStore defaultStore] selectedList] label]);
[labelListName setText:[NSString stringWithFormat:@"List Name: %@", [[[GameStore defaultStore] selectedList] label]]];
[labelCurrentIndex setHidden:YES];
[labelCurrentWord setHidden:YES];
[[self navigationController] setNavigationBarHidden:NO];

[FlurryAnalytics logEvent:@"GameViewController - viewWillAppear"];

[self getNewQuestion];

NSLog(@"ViewWillAppear finish");
[super viewWillAppear:YES];

}

我使用以下代码在应用委托(delegate)中设置 UINavigationalController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
HomeViewController *hv = [[HomeViewController alloc] init];

UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:hv];

// You can now release the itemsViewController here,
// UINavigationController will retain it
[hv release];

// Place navigation controller's view in the window hierarchy
[[self window] setRootViewController:navController];


[navController release];


// Override point for customization after application launch.
[self.window makeKeyAndVisible];
return YES;
}

更新

我不知道发生了什么,但昨晚尝试在模拟器中再次运行该应用程序并且它仍然有这个问题后,我决定保存所有内容并关闭我的计算机,因为已经很晚了。

今天早上我重新打开我的电脑,打开 xcode,清理项目并构建并运行它,我的问题得到解决,-viewWillAppear 被调用。我没有改变任何东西和它的工作。我在 -willShowView 中添加了 NSLog 并且它没有被调用。我不知道为什么突然调用 viewWillAppear。

最佳答案

确保设置了导航 Controller 的委托(delegate),然后使用此函数在您要调用其 viewWillAppear 的类中调用 viewWillAppear:

- (void)navigationController:(UINavigationController *)navigationController 
willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[self viewWillAppear:animated];
}

关于iphone - popviewcontroller 没有调用 viewWillappear,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7564596/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com