在NSSplitViewController内部更改视图 [英] Change views inside NSSplitViewController
问题描述
我正在尝试将我的Objective-C迁移到Mac OS X的应用程序中,并改进Swift知识。陡峭的学习曲线!
I'm trying to migrate my Objective-C and now improving Swift knowledge to an application for Mac OS X. Steep learning curve!
加载 NSSplitViewController
在详细视图中具有不同视图,具体取决于在主视图上按下的按钮。
I'm trying to load a NSSplitViewController
with different views in the "detail view" depending on buttons pressed on the "master view" if you will. Following tutorials and searching for hours has led me to nothing.
我目前有:
import Cocoa
class MainSplitView: NSSplitViewController, BlissWindowDelegate {
var masterViewController: vcMainMenu {
let masterItem = splitViewItems[0] as! NSSplitViewItem
return masterItem.viewController as! vcMainMenu
}
override func viewDidLoad() {
super.viewDidLoad()
masterViewController.delegate = self
}
func userDidSelectFunction(function: String) {
switch function {
case "app":
println("You have selected to load the appointment screen")
case "cust":
println("You have selected to load the customer screen")
case "login":
println("I think I am here and you've clicked login?")
let detailItem = splitViewItems[1] as! NSSplitViewItem
// Trying to load the views here ... but no idea how to
case "admin":
println("You've clicked admin")
default:
println("Nothing here ...")
}
}
}
我正在使用 BlissWindowDelegate
告诉我按钮被按下。然后,我尝试从情节提要中将各种视图加载到 splitViewItem [1]
中。但是没有运气。有人能指出我正确的方向吗?即使是一个体面的参考?
I'm using BlissWindowDelegate
to tell me which button was pressed. I am then trying to load into the splitViewItem[1]
various views from a Storyboard. But having no luck. Can anyone point me in the right direction please? Even for a decent reference? Nothing on Google is seeming to help.
谢谢。
推荐答案
由于听起来好像您可以显示一组特定的详细信息窗格,所以使用 NSTabViewController
可能是完成此操作的最佳方法。
Since it sounds like you have a specific set of detail panes that can be shown, using an NSTabViewController
is probably best way to accomplish this.
基本上,您的 NSSplitViewController
有两个子级:主视图控制器和 NSTabViewController
。对于每个详细信息窗格,选项卡视图控制器都有其自己的子级。由于选项卡视图控制器不应显示自己的选项卡选择UI(主窗格正在执行此操作),因此可以将 tabStyle
设置为。
。故事板看起来像这样:
Basically, your NSSplitViewController
has two children: the master view controller, and a NSTabViewController
. And the tab view controller has its own children for each of the detail panes. Since tab view controller shouldn't present its own tab selection UI (the master pane is doing that), you would set the tabStyle
to be .Unspecified
. The storyboard would look something like this:
您的 MainSplitViewController
也将引用选项卡视图控制器 detailController
。然后在 userDidSelectFunction()
上,将detailController的 selectedTabViewItemIndex
设置为相应的详细信息窗格的。 NSTabViewController
将负责视图转换,包括在窗格之间进行动画处理(如果设置为这样做的话)。
Your MainSplitViewController
would also have a reference to the tab view controller, detailController
. Then on userDidSelectFunction()
, you would set the detailController's selectedTabViewItemIndex
to be that of the corresponding detail pane. NSTabViewController
will take care of the view transition, including animating between the panes if setup to do so.
这篇关于在NSSplitViewController内部更改视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!