如何在同一Mac窗口中显示新的视图控制器? [英] How does one display a new view controller in the same Mac window?

查看:122
本文介绍了如何在同一Mac窗口中显示新的视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Mac开发还很陌生,并且对Xcode 6中的新"storyboard"功能有些困惑,我想做的就是将一个视图控制器从一个视图控制器切换到同一窗口中的另一个视图控制器.截至目前,所有不同的NSViewControllerSegues都将视图控制器显示在新窗口中,无论是模式窗口还是其他窗口.我想做的就是在同一个窗口中进行搜索,就像在iOS上一样(尽管动画过渡并不重要).这将如何实现?

I'm fairly new to Mac development and am slightly confused by the new "storyboard" feature in Xcode 6. What I'm trying to do is segue from one view controller to another in the same window. As of right now, all the different NSViewControllerSegues present the view controller in a new window, be it a modal or just another window. What I'd like to do is just segue within the same window, much in the same way one would on iOS (though an animated transition is not crucial). How would this be achieved?

推荐答案

如果提供自定义segue(NSStoryboardSegue的子类),则可以得到您想要的结果.尽管有一些使用这种方法的陷阱:

If you provide a custom segue (subclass of NSStoryboardSegue) you can get the result you are after. There are a few gotchas with this approach though:

  • 自定义segue将使用presentViewController:animator,因此您需要提供一个动画师对象
  • 由于显示的视图没有单独的Window对象作为后盾,因此您可能需要为其提供自定义的NSView,以捕获不想传播到基础NSViewController的视图的鼠标事件
  • 关于您需要注意的自定义segue的identifier属性,还有一个Swift特有的毛病.
  • the custom segue will use presentViewController:animator so you will need to provide an animator object
  • because the presented view is not backed by a separate Window object, you may need to provide it with a custom NSView just to catch out mouse events that you don't want to propagate to the underlying NSViewController's view
  • there's also a Swift-only glitch regarding the custom segue's identifier property you need to watch out for.

由于似乎没有太多的文档,我做了一个小型演示项目, Swift和Objective-C中的自定义segue示例.

As there doesn't seem to be much documentation about this I have made a small demo project with custom segue examples in Swift and Objective-C.

对于此问题.

这篇关于如何在同一Mac窗口中显示新的视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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