gpt4 book ai didi

iphone - 尝试在 View 之间切换时会看到白屏!

转载 作者:行者123 更新时间:2023-12-03 21:23:42 26 4
gpt4 key购买 nike

我想创建一个非常简单的方法,在基于 View 的应用程序中在 View 之间切换。由于某种原因,当切换 View 时,第一个 View 将被删除,而不是查看第二个 View ,而是看到一个白屏。

这是我的方法:

 FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
self.view = firstViewController.view;
[firstViewController.view removeFromSuperview];
[firstViewController release];
secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
self.view = secondViewController.view;

我不知道为什么会发生这种情况,因为我知道调用了第二个 View 的 ViewDidLoad 方法(我在那里放了一个 NSLog) - 但第二个 View 没有看到!

有什么建议吗?

提前致谢,

Sagift

最佳答案

viewDidLoad 正在执行,因为 initWithNibName:bundle: 调用了它。这并不意味着 View 实际上正在显示。

我通常使用这个(删除初始化/释放逻辑):

[self.view addSubview: firstViewController.view];
[firstViewController.view removeFromSuperview];
[self.view addSubview: secondViewController.view];

关于iphone - 尝试在 View 之间切换时会看到白屏!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2543679/

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