gpt4 book ai didi

ios - 从 Xib 呈现模态视图 Controller

转载 作者:可可西里 更新时间:2023-11-01 05:06:36 26 4
gpt4 key购买 nike

我想显示来自 xib 的模态对话框。显示我的窗口的代码是:

self.vcSettings = [[ViewControllerSettings alloc] initWithNibName:@"ViewControllerSettings" bundle:[NSBundle mainBundle]];  

[self presentModalViewController:self.vcSettings animated:YES];

当它运行时,我得到一个空白屏幕,而不是我的 ViewControllerSettings.xib 中的内容。我想我以某种方式错误地显示了 View 。任何建议表示赞赏。

编辑:

我觉得应该是这样

[self.navigationController presentModalViewController:self.vcSettings animated:YES];

但由于某些原因 self.navigationController 为 nil。

编辑:

Self 是在我的 AppDelegate 中实例化的 UIViewController,如下所示:

UIViewController* viewMain = [[ViewController_iPhone alloc]     initWithNibName:@"ViewController_iPhone" bundle:nil];

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = viewMain;
[self.window makeKeyAndVisible];

最佳答案

您需要创建一个 UINavigationController,将它的 Root View 设置为您要显示的 XIB Controller (在您的情况下为 vcSettings) , 然后呈现 UINavigationController

self.vcSettings =  [[ViewControllerSettings alloc] initWithNibName:@"ViewControllerSettings" bundle:nil];
UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:vcSettings];
[self.navigationController presentModalViewController:controller animated:YES];

关于ios - 从 Xib 呈现模态视图 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10462939/

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