创建启动时不显示的导航控制器

发布于 2024-11-24 13:41:34 字数 150 浏览 1 评论 0原文

我想做这件简单的事情:创建一个 uinavigationcontroller 但在启动时不会显示。假设我想要一个带有“Go”按钮的欢迎屏幕,该按钮可通往 uinavigationcontroller。在我看到的所有示例中,导航控制器似乎立即出现。我应该怎样做呢?

谢谢!

I want to do this simple thing: create a uinavigationcontroller but that doesnt show up on launch. Let's say I want to have a welcome screen with a "Go" button that leads to the uinavigationcontroller. In all the examples that I have seen it looks like the navigationcontroller appears right away. How should I go about doing that?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ら栖息 2024-12-01 13:41:34

如果“显示”是指使用没有可见足迹的导航控制器,那就很简单。只需在根视图控制器中执行此操作:

// Root
- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

对于子视图控制器,您需要执行类似的操作才能在导航栏出现时显示它们。

// Child
- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

对于具有主菜单的应用程序来说,这是一种非常常见的技术,您不想在主菜单视图中显示导航栏。

If by "show up" you mean using a navigation controller with no visible footprint, that's easy. Simply do this in the root view controller:

// Root
- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

For the child view controllers, you need to do something similar in order to display the navigation bar when they appear.

// Child
- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

This is a pretty common technique for apps with main menus where you don't want to display a navigation bar in the main menu view.

給妳壹絲溫柔 2024-12-01 13:41:34

显示导航控制器视图的机制发生在应用委托中的 -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions; 方法中。 NC 被添加为窗口的 rootViewController。
如果你想显示另一个,只需将你的自定义视图控制器设置在 NC 的位置,然后在按下按钮时调用的操作方法中切换两个视图控制器(用 NC 替换第一个自定义视图控制器)。< br>
假设 myCustomController 定义了一个名为 touchButton 的 UIButton 属性:

// in the app delegate
-(BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //self.window.rootViewController = self.navigationController;
    [self.myCustomController.touchButton addTarget:self
                                            action:@selector(switchVC)
                                  forControlEvents:UIControlEventTouchUpInside];
    self.window.rootViewController = self.myCustomController;
    [self.window makeKeyAndVisible];
    return YES;
}

现在在您的应用程序委托中编写一个操作方法:

-(void)switchVC {
    self.window.rootViewController = self.navigationController;
}

The mecanic of displaying the navigation controller's view takes place in the -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions; method, in the app delegate. There the NC is added as the rootViewController of the window.
If you want to display another one, just set your custom view controller right in place of the NC and then switch the two view controllers (replace the first custom view controller with the NC) in the action method called when the button is pressed.
Assuming myCustomController defines a UIButton property called touchButton :

// in the app delegate
-(BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //self.window.rootViewController = self.navigationController;
    [self.myCustomController.touchButton addTarget:self
                                            action:@selector(switchVC)
                                  forControlEvents:UIControlEventTouchUpInside];
    self.window.rootViewController = self.myCustomController;
    [self.window makeKeyAndVisible];
    return YES;
}

Now write in your app delegate an action method :

-(void)switchVC {
    self.window.rootViewController = self.navigationController;
}
你的背包 2024-12-01 13:41:34

在显示隐藏导航栏的视图控制器中,在其他显示导航栏中

[self.navigationController setNavigationBarHidden:YES];

希望这会有所帮助

in viewcontroller that shows go hide navigation bar and in other show navigation bar

[self.navigationController setNavigationBarHidden:YES];

hope this will help

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文