Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mysterd429

macrumors newbie
Original poster
Apr 20, 2008
2
0
Hi all,

I have all of the actions of the different window widgets go to various Objective-C controller classes, and I'd like all of those controllers to call function in a single instance of a main controller class written in C++ for the entire window. (I'm writing a Cocoa front-end to some C++.)

What I was thinking was to have a sub-class of NSWindow that has a pointer to a C++ class representing the overall controller for the window. Each of my Objective-C controller classes has an outlet for their respective widgets. I figured I could use the [NSView window] message for each of the outlets to get at that pointer. Is that a reasonable way of doing that? If so, when should I construct the C++ class? Is adding the awakeFromNib message to my NSWindow sub-class the right time? If so, when should I deconstruct it?

Thanks!
 

Gelfin

macrumors 68020
Sep 18, 2001
2,165
5
Denver, CO
You've created a separate controller class for every widget on the window? That's not really common practice in my experience. Typically you'll have a single controller for your window with several IBOutlets and IBActions.

After you do that there probably isn't any need for a second controller in C++. A typical pattern would be to instantiate your model in awakeFromNib and destroy it in dealloc. I can't guarantee any of that without knowing the specifics of your own project.
 

mysterd429

macrumors newbie
Original poster
Apr 20, 2008
2
0
Thanks for your reply!

You've created a separate controller class for every widget on the window? That's not really common practice in my experience. Typically you'll have a single controller for your window with several IBOutlets and IBActions.

That makes a lot more sense than what I'm doing. I also have an NSTableView widget. If I only have one of these in the window, would I be able to use this controller as the delegate for the NSTableView?

After you do that there probably isn't any need for a second controller in C++. A typical pattern would be to instantiate your model in awakeFromNib and destroy it in dealloc. I can't guarantee any of that without knowing the specifics of your own project.

That pattern makes sense to me. Part of my thinking behind the C++ controller was to make it easier to port to a different platform, but I need to research that more.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.