OGeek|极客世界-中国程序员成长平台

标题: ios - Objective-C:如何在 Xcode 中将 keywindow 设置为不同的 viewcontroller? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 12:11
标题: ios - Objective-C:如何在 Xcode 中将 keywindow 设置为不同的 viewcontroller?

我正在使用 Storyboard 和此代码,但在我当前的 viewConntroller 中没有出现任何内容,而是在我的第一个 viewConntroller 中。任何人都可以将 keywindow 设置为我所在的当前 View 吗?

这是我用来显示我的 UINavigationBar

的代码
[[[UIApplication sharedApplication] keyWindow] addSubview:bar];

提前致谢



Best Answer-推荐答案


您没有将 Viewcontroller 设置为 Window

你需要这样做:

 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    //self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

这是添加 uinavigationcontroller 的方式:

Add a UINavigationBar to a UITableViewController without a UINavigationController

如果你想展示一个新的 View Controller

您只需使用 presentModalViewcontroller:

UIViewController *vc = [[UIViewController alloc] init];
[self.navigationcontroller vc animated:YES];

//我都写好了,看看情况就可以用了

关于ios - Objective-C:如何在 Xcode 中将 keywindow 设置为不同的 viewcontroller?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17493830/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4