On 31/08/2009, at 11:07 AM, BareFeet wrote:

Hi All,

I want to have two NSObjects (controllers) - one for the tableview and all the actions that it needs to perform, and one for the web view. I am having difficulty getting the tableview controller to tell the webview controller to display a particular page. And I can't find anything about this subject in my Cocoa books or on the web. Am I barking up the wrong tree here? Should I only have one controller per window?

I've read the replies but can't get any approach to work. I must be missing something simple.

For example, I have an instance method called "fileString" in my "MyDocument" class, that returns the path to that document. But how do I call it from my "MyController"? In MyController.m, when I say:

#import "MyDocument.h"
...
[MyDocument fileString];

I get a runtime error:

+[MyDocument fileString]: unrecognized selector sent to class.

The error makes sense because I am trying to call an instance method on a class. But how to I refer to the instance of MyDocument that sits in the same nib instance as the MyController that is calling it?

When you stop laughing, can you please lay it out for me.

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?


Hi Barefeet,

First, forget bindings. Clearly you are still at the newbie stage and 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. 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:

//MyDocument.h

@class MyController;

@interface MyDocument : NSDocument
{
    IBOutlet MyController*      the_controller;
}

...

@end

// MyController.h

@class MyDocument;

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

...

@end


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"



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

NSString* file = [the_document fileString];

...and from your document:

[the_controller launchNuclearDevice];


etc, etc.

hope that helps,

--Graham




_______________________________________________

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