My first ObjC/Cocoa application.. and I'm pretty confused.
I'm writing a status item app for our university students to install/uninstall campus printers. They can configure a favorite printer list that should be easily accessible in the status item's menu. So far I have everything in the menus working. Now I'm trying to write the preferences window where they can manage their favorite list.
I have a bunch of Printer objects stored in a NSArray in a singleton object PrinterData. Predicate methods allow me to get arrays of the favorite, and not favorite printer objects.
PrinterController draws the Printer objects in the status item menu.
PreferenceController has a nib with several views (toolbar items), including a view for the favorites. I've decided to show all printers in a split-view style, with their names in a NSTableView on the left, and additional data on the right. I'll also place a checkbox on the right to control whether its a favorite printer, and hopefully use notifications to be able to redraw the status item menu. Maybe some bold font binding on the left..
I'm binding the TableView content to an ArrayController to display the objects from PrinterData, which is also an object in the nib.
Could I get some criticism of how I've organized this? Suggestions for any aspect?
You could use an NSWindowController to manage several NSViewController objects. Apple has an excellent example here that demonstrates that MVC pattern.
Following Apple's example, within any view controller you can switch to another view controller like this:
MainWindowController* windowController = [[[self view] window] windowController];
[windowController changeViewController:kLoginViewController];
Basically your Application delegate creates a window controller, which creates view controllers for the desired views you would like to have. That way, if you ever need to add or remove views the process is quite painless.
You should look into Core Data Applications if you want access to the same data from multiple views. An alternative would be to store the NSArray of printer objects in the Application Delegate and pass a reference to them to whichever view needs to access the objects, but I would recommend Core Data over that approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With