1

I'm just getting into desktop Cocoa development (I have experience with iOS development). If this question seems basic, forgive me.

That being said, I'm dealing with a large program with lots of calculations and functionality to deal with. There are almost a dozen views, organized with an NSTabView. Rather than dumping everything into one monstrosity of a class and creating a XIB file that brings my system to its knees (Xcode apparently isn't that efficient…who knew? :P). I'd like for each tab to be its own NSViewController with accompanying XIB; as such, I'd like to load each tab's view from the corresponding XIB.

I'm thinking of this in terms of UITabBarController, but this doesn't seem to work (there isn't an NSTabViewController as far as I could find). I'm not sure how to do this (or even if it's possible—but I can't be the only one with this issue?), and I'd appreciate any assistance. Thanks!

Update: I tried assigning the controller's view to the tab's view, but quickly realized that wouldn't get me anywhere. Is it worth creating an NSTabViewController from scratch, or is there a solution out there?

FeifanZ
  • 16,250
  • 7
  • 45
  • 84
  • +1 great question I am struggling with the same problem at the moment, same background with iOS etc. – James Jun 30 '13 at 10:56

2 Answers2

3

Cocoa development on the desktop has some major differences compared to iOS development. One of them is the use of view controllers - they aren't strictly necessary - and when you use them you can just stick to a generic NSViewController regardless of what kind of view it contains. All of the methods you need to control the tab view are in the NSTabView class - not the controller.

Having said that, putting 12 views in to a tabview sounds like a painful way to interact with a program. Have you thought about a source-detail type setup (think itunes or mail with their sidebars - each entry in the sidebar corresponds to a different view)?

sosborn
  • 14,676
  • 2
  • 42
  • 46
  • Thanks for the answer. I haven't considered it, but now that you mention it, I will.…Err, how would I do that? What classes would I use to get started with? – FeifanZ Sep 08 '11 at 00:28
  • It is essentially an NSSplitView that has an NSTableView on the left and an NSView on the right. The right-hand side really depends on your data. – sosborn Sep 08 '11 at 01:12
  • By the way, you might want to look at this: http://stackoverflow.com/questions/1670727/trouble-creating-an-itunes-style-source-list-in-cocoa – sosborn Sep 08 '11 at 01:14
1

I've ditched the tab bar, and as per sosborn's suggestion, I have used a split view—or rather I've put a table view on the side, and a custom view taking up most of the screen. Then, in my AppDelegate, I have individual controllers as ivars (I need individual controllers because there are a lot of calculations involved, and I don't want to have a monster class handling them all). They'll be lazily loaded, and the view will be assigned to the current controller's view as necessary.

FeifanZ
  • 16,250
  • 7
  • 45
  • 84