(我正在使用故事板和 swift。)
我目前有一个 NSWindowController,其中有一个 NSTabViewController 作为 contentViewController。
我现在尝试通过代码从 NSWindowController 更改选项卡
let tabController = self.contentViewController as! NSTabViewController
tabController.tabView.selectTabViewItemAtIndex(1)
但 TabView 不会改变视图。
我使用API错误吗?
我找到了一个论坛帖子 https://forums.developer.apple.com/thread/9991关于这个话题。设置的时候好像有bugtabView
索引与使用相结合NSTabViewController
.
他们的解决方案是通过控制器本身而不是其 tabView 选择选项卡。
这可以通过使用来完成selectedTabViewItemIndex
财产。
所以你的代码如下:
if let contentViewController = self.contentViewController as? NSTabViewController {
contentViewController.selectedTabViewItemIndex = 1
}
I am going to file a radar on this and you should do the same. This really seems to be a bug, not a misuse of the API.
Update 11/10/2016:
The issue seems to be fixed partly. (macOS Sierra 10.12.1) The method now selects the tab, but the selection in the tab bar does not update..
更新 11/16/2016:
据苹果公司称,这不是一个错误,而是有意为之的行为。他们正在更新文档。
使用 tabViewController 时,控制器拥有选项卡 UI(分段控件、工具栏等),而不是 tabView 本身。事实上,tabView 没有选项卡样式,因此它只处理内容视图之间的切换。
我们使用内部错误报告 29184908 来跟踪更新文档,指出 selectedTabViewItemIndex 应专门在此上下文中使用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)