将NSTabViewItem中的NSTabViewItem副本添加到同一NSTabView中 [英] Adding a copy of an NSTabViewItem from an NSTabView into the same NSTabView
问题描述
我正在创建一个简单的Web浏览器,并希望实现标签页.为此,我正在使用 NSTabView
.我基本上希望每个选项卡都有一个 WebView
来显示已加载的网站.我仅从一个选项卡开始,并希望在创建新选项卡时添加第一个选项卡的精确副本.我尝试了类似 tabView.addTabViewItem(tabView.tabViewItemAtIndex(0).copy()as NSTableViewItem)
之类的东西,但是却收到了无法识别的选择器发送到实例
的错误.我已经查看了 NSTableView
和 NSTableViewItem
的文档,但不知道该怎么做.
I'm creating a simple web browser and would like to implement tabs. For this purpose, I'm using an NSTabView
. I basically want each tab to have a WebView
that will show the website loaded. I'm starting with only one tab and want to add an exact copy of the first one when I create a new tab. I tried something like tabView.addTabViewItem(tabView.tabViewItemAtIndex(0).copy() as NSTableViewItem)
but I'm getting an unrecognised selector sent to instance
error. I've check the documentation for both NSTableView
and NSTableViewItem
but can't figure out how to that.
编辑我的整个错误看起来像这样:
EDIT My whole error looks like this:
015-03-14 17:15:57.884 Browser[1955:56547] -[NSTabViewItem copyWithZone:]: unrecognized selector sent to instance 0x600000100b40
2015-03-14 17:15:57.884 Browser[1955:56547] -[NSTabViewItem copyWithZone:]: unrecognized selector sent to instance 0x600000100b40
推荐答案
Thanks to the answer on Copy NSView in cocoa and @MattyAyOh, I solved my problem by doing:
var data = NSKeyedArchiver.archivedDataWithRootObject(view)
var newView = NSKeyedUnarchiver.unarchiveObjectWithData(data) as NSView
newTab.view = newView
tabView.addTabViewItem(newTab)
这篇关于将NSTabViewItem中的NSTabViewItem副本添加到同一NSTabView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!