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

Eraserhead

macrumors G4
Original poster
Nov 3, 2005
10,434
12,250
UK
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

Moderator emeritus
Jun 15, 2000
7,958
7
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

macrumors G4
Original poster
Nov 3, 2005
10,434
12,250
UK
To expand question 2, obviously in AppController I can put:
Code:
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

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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
Code:
AnotherNibFileController *anfc=[[AnotherNibFileController alloc] initWithWindowNibName:@"AnotherWindow"];
[anfc registerParent:self];
 

Eraserhead

macrumors G4
Original poster
Nov 3, 2005
10,434
12,250
UK
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

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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

macrumors G4
Original poster
Nov 3, 2005
10,434
12,250
UK
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 :).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.