隐藏NSApplication窗口的内容视图,以便导航到主屏幕 [英] Hide content view of NSApplication window in order to navigate to main screen

查看:322
本文介绍了隐藏NSApplication窗口的内容视图,以便导航到主屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最初,我有自己的应用程序主窗口上的设置,即图像视图(为背景),它有一组按钮。现在当用户点击按钮时,相应的课程被启动,即用户被导航到相应的屏幕,即我将视图添加到窗口的内容视图....

Initially I have my own setup on application main window, i.e. an image view(for background) and on it I have a set of buttons. Now when user taps on the buttons, respective lesson is launched, i.e. user is being navigated to the corresponding screen, i.e. I add the view to window's content view....

[self.window.contentView addSubview:self.lessonScreen.view];

实际上,我知道有一种方法在窗口上进行视图我们的意见(为导航)。然后,为了导航到主屏幕(窗口),我们可以简单地隐藏该视图。但我遵循通过窗口的内容视图添加视图的方法。

Actually I know there is an approach of taking a view(custom view) on window, keeping on adding our views to that(for navigation). Then for navigating to main screen(window), we can simply hide that view. But I am following the approach of adding views through window's content view.

但是视图增加了,但是我不能导航到主屏幕,我尝试了各种方法和以下是我遵循的方法之一:

However the views get added fine, but I am not able to navigate to home screen, I tried various ways and the below is one of the method I followed:

[[window contentView] setHidden:YES];

现在发生的是窗口变为空白,主视图也消失了。

Now what happens is the window becomes blank, the main view also vanishes.

我也试图在Windows内容视图子视图枚举视图,删除相同,但我得到了一个崩溃,更多的同一个空白屏幕也出现在这种情况下:(

I also tried to enumerate views in windows content view subviews and remove the same, but I am getting a crash and more over the same blank screen appears in this case too :(

我也遇到过这里没有解决我的问题。

I have also gone through questions here and there which didn't solve my problem.

有人可以建议我一个方法,从主窗口中删除内容视图,为了跳转到我的主屏幕,因为我有主菜单按钮用于用户导航。

Can some one please suggest me a way to remove content view from main window in order to jump to my main screen as I have main menu button for user navigation.

任何帮助都非常感谢,谢谢:)

Any help is greatly appreciated, thanks :)

推荐答案

我没有创建我自己的类来处理主视图控制器。

My basic foundation was not proper, previously I didn't create my own class to handle main view controller. That's the reason why things went weird.

只需创建我们自己的NSViewController类,创建我们的主菜单视图,然后添加与窗口的内容视图相同的<$我们的appDelegate文件的方法c $ c> - (void)applicationDidFinishLaunching:(NSNotification *)aNotification ,即:

Just create our main menu view by creating our own NSViewController class, then add the same as our window's content view by adding in - (void)applicationDidFinishLaunching:(NSNotification *)aNotification method of our appDelegate file, i.e.:

self.mainViewController = [[MainViewController alloc]initWithNibName:@"MainViewController" bundle:nil];
self.window.contentView = _mainViewController.view;

现在我们开始向窗口的内容视图添加自己的视图,以便导航到主屏幕,我们不需要隐藏内容视图,而是将我们的主视图分配为窗口的内容视图:

Now that we have started adding our own views to window's content view, in order to navigate to home screen, we need not hide the content view, instead assign our home view as the window's content view:

-(IBAction)topicButton:(id)sender
{
    [AppDelegate sharedInstance].mainViewController = [[MainViewController alloc]initWithNibName:@"MainViewController" bundle:nil];
    [[AppDelegate sharedInstance].window setContentView:[AppDelegate sharedInstanceofAppDelegate].mainViewController.view];
}

注意:此处[AppDelegate sharedInstance]我们的应用程序委托类的实例,即:

Note: Here [AppDelegate sharedInstance] is the instance of our app delegate class, i.e.:

+(AppDelegate *)sharedInstance
{
    if (!sharedAppDelegate) {
        sharedAppDelegate = (AppDelegate *)[[NSApplication sharedApplication]delegate];
    }
    return sharedAppDelegate;
}

就是这样,我们现在可以将用户导航到主屏幕主菜单按钮已点击:)

That's it, we can now navigate the user to home screen when ever topic or main menu button's clicked :)

希望它有帮助,感谢一个和所有的关注:)

Hope it helps, thanks to one and all for the concern :)

这篇关于隐藏NSApplication窗口的内容视图,以便导航到主屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆