PDA

View Full Version : Multiple nib files, some (well 2) questions




Eraserhead
Feb 13, 2007, 02:47 PM
After finding that having one nib file for everything in my program wasn't exactly the greatest idea I ever had I have a couple of questions as the documentation for mulitple nibs seems to be a bit lacking.

1) If I have a controller in one file (Say MyDocument.nib) how to I access it in another nib file (Say AnotherNibFile.nib).

2) So I don't have (!)'s in my nib (and to make stuff less confusing), I want to have two controllers to go with my two nib files (say MyDocController and AnotherNibFileController) for simplicity), now if MyDocController loads first, I can reference AnotherNibFileController in it, but how would I go back the other way?



kainjow
Feb 13, 2007, 04:02 PM
Accessing one controller from another is a matter of design. If you give us more specific examples it may help. Generally, I have a main controller class for the entire app, and that has other classes it manages (AppController -> WindowControllers, PreferencesController). So the main controller creates instances of the others. If the other controllers need to access something from the main controller, generally you can design it so they both don't have access to each other. It all depends on what you're actually doing in your code.

Eraserhead
Feb 13, 2007, 04:05 PM
To expand question 2, obviously in AppController I can put:

AnotherNibFileController *anfc=[[AnotherNibFileController alloc] init];


And then I can call methods in anfc using [anfc someMethodInAnotherNibFileController];

But how do I call an instance method in AppController (for example to get an arrayController, or a tabView) from the instance I have just created of AnotherNibFileController?

I would need to go both ways, as I also need to access the array controller in most of my methods, which would return me to one nib/controller...

robbieduncan
Feb 13, 2007, 04:08 PM
You don't. In general this would be bad design. Note that you should be using initWithWindowNibName: otherwise the nib wouldn't get loaded. If you absolutely have to do what you are suggesting add an instance method to the subcontroller called registerParent:(id) parent or something similar and call this passing the main controller to setup the two way relationship.

So you could do this in AppController

AnotherNibFileController *anfc=[[AnotherNibFileController alloc] initWithWindowNibName:@"AnotherWindow"];
[anfc registerParent:self];

Eraserhead
Feb 13, 2007, 04:15 PM
If you absolutely have to do what you are suggesting add an instance method to the subcontroller called registerParent:(id) parent or something similar and call this passing the main controller to setup the two way relationship

So is their another (better) way to load an object in MyDocument.nib from AnotherNibFileController? Unless I import AnotherNibFileController into MyDocument.nib, which means I might as well stick everything in AppController, the problem with this is that then I have loads of undefined methods in AppController which don't link to anything in each nib which is very confusing to code...

robbieduncan
Feb 13, 2007, 04:19 PM
Perhaps if you give us some sort of concrete example of what you are trying to do we can give you a solution. You can't really do what you are trying to do. If you want to have the controls in two windows "talk" then the solution proper solution is to do it via the controller or model layer. If you use bindings then if the controls in one window update the model the other windows bound to that data will automatically update.

Eraserhead
Feb 13, 2007, 04:21 PM
Perhaps if you give us some sort of concrete example of what you are trying to do we can give you a solution. You can't really do what you are trying to do.

OK, I think I need to come back to you on that, I'll try and think of another solution, thanks for your help :).