Hi Graham and all,

I also tried to use bindings, which I've made work well for linking text views, table columns, even outline view columns, to data in my model. But I can't seem to set up bindings to link an instance variable in one controller to another controller. So I guess bindings are only for linking view objects to model objects, yes?

First, forget bindings... bindings is really an advanced topic, so I suggest you'll be better off leaving it alone for now. Bindings are mostly designed for handling the view<-->controller connections.

Actually, as I mentioned, I've had great success with bindings for linking view objects to data. I am actually surprised at how bindings seems to always be taught as an advanced topic, whereas I think it should be introduced much earlier to newbie Cocoa programmers, especially since it eliminates so much code, but that's another story.

I just wondered whether bindings could be used to link instance variables in two controllers, but I guess not.

In this case you have a controller<-->controller connection, which is likely to be a lot simpler.

You have two controllers. Each controller can have an IBOutlet to the other one. Just declare the outlets then wire them up in your nib, e.g:

I kinda got that, but missed what exactly to wire up...

// MyController.h

@class MyDocument;

@interface MController : NSObject
{
   IBOutlet MyDocument*    the_document;
}

...

@end

...
ahh, now that makes sense. That's what I was missing. I was trying to add IBOutlets for instance variables but needed to instead add IBOutlets for the class (eg MyDocument). Has this been documented anywhere? I couldn't find it. I would have thought it a common requirement, or is there a better approach to sharing data between controllers in the same nib?

When I try to compile the above, I get an error:

expected specifier-qualifier-list before 'MyDocument'

If I change the "MyDocument*" to "id", it works, but what's the problem?

Once you have added the outlets to your classes, they will be visible in IB, so just ctrl-drag from one object to the other and choose the outlet to connect it. In the .m files, #import the header for the other class:

#import "MyDocument.h"

Is this really necessary? It compiles without it. I did it anyway.

In your code, you can now do things like this, from your controller:

NSString* file = [the_document fileString];

the_document is showing as value nil. It doesn't seem to be linked to the instance of MyDocument. Am I missing something?

Thanks for all your help,
Tom
BareFeet

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to