views:

137

answers:

4

Hi,

I've a fairly complex window that is backed by a controller class that is obviously growing to meet the needs of my view window. While I believe I am sticking to proper MVC I'm still having problems managing a fairly largish controller class.

How do you breakdown your objects? Maybe use Categories? For example, one category to handle the bottom part of the window, another category to handle my NSOutlineView, another category to handle a table, and so on and so forth?

Any ideas or suggestions are welcome.

A: 

Categories are ideal for this. Create a new file for each category, and group them by functionality, as you suggested.

Ben Gottlieb
A: 

I've tried using Categories in situations like this and I just end up confusing myself, wondering how in the world I'm calling that method when it's "obviously" not in the class I'm looking at.

I'd recommend liberal use of #pragma mark in your source code. Makes it super-easy to browse through all your methods.

kubi
I'm using pragmas, but there are times when I just need less code in my way.
Rui Pacheco
+6  A: 

It sounds like it's a complex window controller that's growing to unmanageable proportions? This is getting to be a more common issue because of applications which, like the iApps, do most of their work in a single window.

As of Leopard, the recommended way of breaking it down is to factor out each part of the window into its own NSViewController subclass. So, for example, you'd have a view controller for your outline view, and a view controller for each of your content views, etc.

Also, I'd like to second the use of #pragma marks to divide code files up into segments, and in addition to categories, I also like to use class extensions for private methods.

Alex
View controllers really are a great solution for this problem. Your window controller will basically be responsible for setting up and passing data between view controllers, while the view controllers handle the majority of the logic in separate, manageable chunks.
Marc Charbonneau
Be aware that UIViewController event messages like -view{Did,Will}Load, -view{Did,Will}Appear, etc. are only sent to the top level view controllers. If you want the lower level view controllers to receive them, you have to hook those messages into the top level's implementation.
Giao
+2  A: 

It's a simple answer, but the code folding feature of the Xcode IDE can be handy for focusing your attention on sections of a class. Another little thing that might help is going to View->Code Folding and turning on Focus Follows Selection. This makes it so the background color of the scope of your current selection is white while everything else is shades of gray.

Preston
How can I set this project-wide?
Rui Pacheco
I don't know of a way to enable Focus Follows Selection by default for the whole project. If it helps, the hotkey is: Ctrl+Option+Command+F.
Preston