objective-ccocoaswiftnstabview

Adding a copy of an NSTabViewItem from an NSTabView into the same NSTabView


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

Solution

  • 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)