问题描述
(我正在使用情节提要和快捷方式。)
我目前有一个NSWindowController,其中有一个NSTabViewController作为contentViewController。
我现在正在尝试通过使用
let tabController = self.contentViewController作为代码通过代码从NSWindowController更改选项卡! NSTabViewController
tabController.tabView.selectTabViewItemAtIndex(1)
但TabView不会更改视图。
我使用的API错误吗?
I找到了关于此主题的
更新11 / 16/2016 :
据Apple称,这不是错误,而是预期的行为。他们正在更新文档。
(I'm using storyboards and swift.)
I currently have a NSWindowController which has a NSTabViewController as contentViewController.I am now trying to change the Tabs from the NSWindowController via code using
let tabController = self.contentViewController as! NSTabViewController
tabController.tabView.selectTabViewItemAtIndex(1)
but the TabView doesn't change the view.
Am I using the API wrong?
I found an forum post about this topic. There seems to be a bug when setting the tabView
index in combination with using NSTabViewController
.
Their solution is to select the tab via the controller itself instead of its tabView.This can be done by using the selectedTabViewItemIndex
property.
So your code would be the following:
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..
Update 11/16/2016:
According to Apple, this is not a bug but intended behaviour. They are updating the documentation.
这篇关于从父视图控制NSTabViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!