Re: Two controllers in a window, how do I get one to run a function in another?

2009-09-01 Thread BareFeet

Hi again Graham and anyone else interested,

Yes, I've done that, control dragged from MyController to File's  
Owner and selected the_document. For simplicity, I'm just creating  
the_document in MyController (I've no need for MyDocument to refer  
to the_controller).


I still get nil for the_document at runtime.


OK, my antennae are twitching. You're going to have to show your  
code, because it sounds like you're doing something very strange here.


You say you're creating the document in your controller. Huh?


No, I'm not specifically creating the document (ie an instance of  
NSDocument). I'm just creating the_document instance variable, as per  
your code sample. Perhaps my use of the word creating was  
misleading, sorry.


To try to isolate the issue, I created a Refresh button and hooked  
it up to a refresh method in MyController. It just calls init (as  
below). When the program runs and instantiates a document that I open,  
debugging the init call shows the_document as nil. But when I click  
Refresh to call init again, it shows the_document as not nil and  
fileString is assigned correctly etc.


So perhaps it's a problem with the instantiation?

My code is below.

Thanks for your help with this. This is one thorn in a project port  
(from AppleScript Studio) that is otherwise going very well.


Tom

//  MyDocument.h

#import Cocoa/Cocoa.h

@interface MyDocument : NSDocument
{
}
@end


//  MyDocument.m

#import MyDocument.h

@implementation MyDocument
// usual template code
@end


//  MyController.h

#import Cocoa/Cocoa.h

@class MyDocument;

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

- (IBAction) refresh:(NSButton*)sender;

@end


//  MyController.m

#import MyController.h
#import MyDocument.h

@implementation MyController

- (IBAction) refresh:(NSButton*)sender
{
[self init];
}

- (id) init
{
[super init];
NSString* fileString = [[the_document fileURL] path];
// more code that uses fileString
}

- (void) dealloc
{
[super dealloc];
}

@end

___

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


Re: Two controllers in a window, how do I get one to run a function in another?

2009-09-01 Thread Graham Cox


On 01/09/2009, at 4:13 PM, BareFeet wrote:

To try to isolate the issue, I created a Refresh button and hooked  
it up to a refresh method in MyController. It just calls init (as  
below). When the program runs and instantiates a document that I  
open, debugging the init call shows the_document as nil. But when I  
click Refresh to call init again, it shows the_document as not nil  
and fileString is assigned correctly etc.


So perhaps it's a problem with the instantiation?

My code is below.

Thanks for your help with this. This is one thorn in a project port  
(from AppleScript Studio) that is otherwise going very well.


Tom

//  MyDocument.h

#import Cocoa/Cocoa.h

@interface MyDocument : NSDocument
{
}
@end


//  MyDocument.m

#import MyDocument.h

@implementation MyDocument
// usual template code
@end


//  MyController.h

#import Cocoa/Cocoa.h

@class MyDocument;

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

- (IBAction) refresh:(NSButton*)sender;

@end


//  MyController.m

#import MyController.h
#import MyDocument.h

@implementation MyController

- (IBAction) refresh:(NSButton*)sender
{
[self init];
}



This is very suspect. You can't send a message to an object that  
hasn't already been inited, and you can't init twice. So one of those  
things is wrong here.


Why don't you just do:

- (IBAction) refresh:(id) sender
{
NSLog( @file string = %@, [the_document fileString]);
}

and see what you get?


- (id) init
{
[super init];
NSString* fileString = [[the_document fileURL] path];
// more code that uses fileString
}


the_document is not going to be valid at init time, because your  
init method isn't initialising it. That's why it's nil. However, since  
the document is made for you, and the controller is loaded from the  
nib, you can't set it up here anyway. The nib load itself will set it  
up, assuming you have it connected in IB.


Also, as an aside, pay attention to the correct idiom for init methods:

- (id) init
{
self = [super init];
if( self )
{
// ... local ivar initialisation ...
}

return self;
}



The ivar the_document won't be valid until at least -awakeFromNib is  
called. That's the earliest point you can access it.


I think you're over-thinking this. Is MyController an object in the  
nib? If so, connect the_document to File's Owner and you're done. By  
the time your document is ready to use, the controller will be valid,  
exist, and be working. Init time for any of these objects is too early  
- debugging in there won't tell you much because at that time the nib  
hasn't been fully loaded so none of the outlets will have been set.  
Also, for most objects instantiated from a nib, -init isn't even  
called, -initWithCoder: is instead.


If on the other hand you're instantiating MyController in code, stop  
it, and just add it in IB. If you instantiate it yourself you have to  
connect up the outlets yourself, and in that case you're back to  
square one - trying to find the document without a reference to it. It  
can be done, but it's long-winded and unnecessary. Just instantiate  
the controller in the nib, wire up the outlet and you're done.


This is all thoroughly covered in the documentation on nib concepts.

--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


Re: Two controllers in a window, how do I get one to run a function in another?

2009-09-01 Thread Chase Meadors

Define an outlet in MyController

IBOutlet id documentController;

Connect it to MyDocument in interface builder. Then call:

[documentController fileString];

---

This is a minor annoyance when using multiple controllers, as they  
will probably need information from the other controllers.


On Aug 30, 2009, at 8:07 PM, 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?


Thanks,
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/c.ed.mead%40gmail.com

This email sent to c.ed.m...@gmail.com


___

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


Re: Two controllers in a window, how do I get one to run a function in another?

2009-09-01 Thread BareFeet

Hi Graham,

To try to isolate the issue, I created a Refresh button and  
hooked it up to a refresh method in MyController. It just calls  
init (as below). When the program runs and instantiates a  
document that I open, debugging the init call shows the_document as  
nil. But when I click Refresh to call init again, it shows  
the_document as not nil and fileString is assigned correctly etc.


So perhaps it's a problem with the instantiation?


The ivar the_document won't be valid until at least -awakeFromNib  
is called. That's the earliest point you can access it.


That did the trick. I moved the code (referring to the_document) to  
run after/in awakeFromNib, rather than in the init method.


I think you're over-thinking this. Is MyController an object in the  
nib?


Yes.


If so, connect the_document to File's Owner and you're done.


Already done.

By the time your document is ready to use, the controller will be  
valid, exist, and be working.


It is working now.

Init time for any of these objects is too early - debugging in there  
won't tell you much because at that time the nib hasn't been fully  
loaded so none of the outlets will have been set.


That was the problem.


If on the other hand you're instantiating MyController in code


Nah, wasn't over-thinking ;-)

Thanks a lot Graham for your time and patience. I really appreciate  
it. As I mentioned, this has been one repeating gap in my knowledge  
(accessing one object's ivars or methods from another in the same  
nib). I had seen the IBOutlet approach mentioned in forums, but  
nothing really laid it out.


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


Re: Two controllers in a window, how do I get one to run a function in another?

2009-08-31 Thread Graham Cox


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


Re: Two controllers in a window, how do I get one to run a function in another?

2009-08-31 Thread BareFeet

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


Re: Two controllers in a window, how do I get one to run a function in another?

2009-08-31 Thread Graham Cox


On 01/09/2009, at 12:25 PM, BareFeet wrote:

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).



Whaaa? You're probably getting your terminology confused, but the  
above makes no sense to me. IBOutlets *are* instance variables. You  
don't/can't add an IBOutlet for an instance variable. The presence  
of IBOutlet is merely a marker that allows IB to parse the file. If  
you look up its definition you'll see it evaluates to nothing.


You are also not adding an IBOutlet for the class. You are adding an  
instance variable, tagged as an outlet, which will point to the  
MyDocument instance.


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?


It must be documented somewhere, but it's also fundamental to the way  
Cocoa works with nibs, so usually it's something you learn about very  
early on. A better approach? Possibly, but this is generally what I  
do, and probably most people do - it's simple, direct and doesn't do  
anything very magic though I guess nib loading itself can seem quite  
magical at first.



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?


Did you include the @class MyDocument; line? That's important - it's a  
forward declaration, which informs the compiler that the MyDocument*  
is merely a pointer, and so it doesn't need to know anything else  
about the class - it has all it needs to proceed to lay out this  
object. You can use id, which is a bit like void*, an anonymous type  
that will shut the compiler up, but it's better to type things  
specifically where you can do so, and here is one such place.



#import MyDocument.h


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



Yes, it's really necessary. If you want to properly call the methods  
of the MyDocument class, the code needs to know what they are. By  
typing the_document as id, you allowed the thing to compile using some  
built-in assumptions about what the methods (of class 'id') look like,  
but typically those assumptions are false, so it might work, or it  
might lead to hard to find bugs that keep you guessing for days or  
weeks. If you correctly type the ivar as MyDocument*, it then becomes  
essential to #import its header in your code in order to call its  
methods, but at the same time it eliminates a major source of bugs at  
a stroke.



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?



Well, have you actually linked it to the instance of MyDocument? If  
these objects exist as part of the nib (which is the simplest  
approach) then you link them together in Interface Builder by ctrl- 
dragging from one to the other. In the case of the document class,  
it's File's Owner in the nib. The other controller would typically  
be dragged in as an NSObject (blue cube icon) and have its class set  
to MyController. IB will display the outlets the_document and  
the_controller and then it's up to you to connect them.


--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


Re: Two controllers in a window, how do I get one to run a function in another?

2009-08-31 Thread BareFeet

Hi Graham and all,

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).


Whaaa? You're probably getting your terminology confused


but the above makes no sense to me. IBOutlets *are* instance  
variables. You don't/can't add an IBOutlet for an instance  
variable. The presence of IBOutlet is merely a marker that allows  
IB to parse the file. If you look up its definition you'll see it  
evaluates to nothing.


Yes, bad terminology, sorry. I know IBOutlets are just a label/marker  
for instance variables which Interface Builder recognises. What I  
meant was that I was trying to add in MyController the IBOutlet label  
for an instance variable in the MyDocument class, but should have  
instead labeled an instance of the MyDocument class itself. I don't  
know if that's any clearer.


You are also not adding an IBOutlet for the class. You are adding an  
instance variable, tagged as an outlet, which will point to the  
MyDocument instance.


Yes, that's what I meant ;-)


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?


Did you include the @class MyDocument; line?


Doh!, no, missed that. Thanks for that.

That's important - it's a forward declaration, which informs the  
compiler that the MyDocument* is merely a pointer, and so it doesn't  
need to know anything else about the class - it has all it needs to  
proceed to lay out this object.


Again, I'd like to see where this is documented, in the context of  
linking controllers. Thanks so much for the tip.


You can use id, which is a bit like void*, an anonymous type that  
will shut the compiler up, but it's better to type things  
specifically where you can do so, and here is one such place.


Yes, I'm familiar with id being like void, used as a non-specific  
pointer etc. I prefer to use specific classes, but just used id  
temporarily to isolate the problem. I've specified the type now that  
the error is gone (thanks to @class).



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?


Well, have you actually linked it to the instance of MyDocument? If  
these objects exist as part of the nib (which is the simplest  
approach) then you link them together in Interface Builder by ctrl- 
dragging from one to the other. In the case of the document class,  
it's File's Owner in the nib. The other controller would typically  
be dragged in as an NSObject (blue cube icon) and have its class set  
to MyController. IB will display the outlets the_document and  
the_controller and then it's up to you to connect them.


Yes, I've done that, control dragged from MyController to File's Owner  
and selected the_document. For simplicity, I'm just creating  
the_document in MyController (I've no need for MyDocument to refer to  
the_controller).


I still get nil for the_document at runtime.

Any other ideas?

Thanks,
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


Re: Two controllers in a window, how do I get one to run a function in another?

2009-08-31 Thread Graham Cox


On 01/09/2009, at 2:55 PM, BareFeet wrote:


Doh!, no, missed that. Thanks for that.

That's important - it's a forward declaration, which informs the  
compiler that the MyDocument* is merely a pointer, and so it  
doesn't need to know anything else about the class - it has all it  
needs to proceed to lay out this object.


Again, I'd like to see where this is documented, in the context of  
linking controllers. Thanks so much for the tip.


Well, it isn't specifically documented in that context, as it's a  
generic feature of the Objective-C language, used for the purpose I  
described - namely, to avoid a dependency between headers when all  
that the compiler really needs to know at that point is the pointer  
size. Most other languages have similar features.


Well, have you actually linked it to the instance of MyDocument? If  
these objects exist as part of the nib (which is the simplest  
approach) then you link them together in Interface Builder by ctrl- 
dragging from one to the other. In the case of the document class,  
it's File's Owner in the nib. The other controller would  
typically be dragged in as an NSObject (blue cube icon) and have  
its class set to MyController. IB will display the outlets  
the_document and the_controller and then it's up to you to  
connect them.


Yes, I've done that, control dragged from MyController to File's  
Owner and selected the_document. For simplicity, I'm just creating  
the_document in MyController (I've no need for MyDocument to refer  
to the_controller).


I still get nil for the_document at runtime.



OK, my antennae are twitching. You're going to have to show your code,  
because it sounds like you're doing something very strange here.


You say you're creating the document in your controller. Huh? I could  
just about imagine the other way around would be OK, but this?  
Nooo. The document is created for you by NSDocumentController, and  
that in turn uses your info.plist to find out what class of document  
is needed for what types of file. The document then loads the  
associated nib, and becomes File's Owner. You will not be creating a  
document anywhere - it's invariably done for you. Realise that the  
objects in a nib are real - you don't have to instantiate them in your  
code - doing so is an error. The objects are instantiated when you  
drag them into the nib window in IB.


The document might then own the controller, and that would be either  
instantiated in the nib (by far the simplest approach) or in your code  
and hooked up manually. Sound like something somewhere is seriously  
bass-ackwards...


Post the code where you create the document.

--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


Re: Two controllers in a window, how do I get one to run a function in another?

2009-08-30 Thread BareFeet

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?


Thanks,
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


Two controllers in a window, how do I get one to run a function in another?

2009-08-27 Thread Support
I'm writing an application which has one window, with an NSTableView and a 
WebView in it.  The NSTableView will contain a list of URLs and site 
descriptions and the WebView will display the URL when it's clicked on in the 
NSTableView.  So far, so simple - especially if the NSTableView and WebView are 
in the same object.

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'd be most grateful for any enlightenment.

___

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


Re: Two controllers in a window, how do I get one to run a function in another?

2009-08-27 Thread Graham Cox


On 27/08/2009, at 11:55 PM, Support wrote:

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'd be most grateful for any enlightenment.



One controller for each view sounds like a good plan. There's  
certainly no requirement that you can have only one controller per  
window.


It's up to you how your controllers communicate. For example, your  
Webview controller could have a method showURL: which accepts a  
NSURL object, and the first controller can turn the selection into one  
and pass it to the second. That's all there is to it pretty much. You  
could probably make it nice and complicated and involve bindings and  
so on, but why bother? K.I.S.S...


--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


Re: Two controllers in a window, how do I get one to run a function in another?

2009-08-27 Thread Sherm Pendley
On Thu, Aug 27, 2009 at 10:04 AM, Graham Coxgraham@bigpond.com wrote:

 On 27/08/2009, at 11:55 PM, Support wrote:

 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'd be most grateful for any enlightenment.


 One controller for each view sounds like a good plan. There's certainly no
 requirement that you can have only one controller per window.

Also, there's no requirement that outlets refer to graphical widgets
either. You can create outlets that refer to other controller objects
too, and connect them in Interface Builder.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
___

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


Re: Two controllers in a window, how do I get one to run a function in another?

2009-08-27 Thread bryscomat

The solution I'd recommend is in Cocoa Bindings.
http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/CocoaBindings.html

A view controller per view is a good idea. For some more samples on  
that, you can look at KTUIKit.

http://katidev.com/blog/ktuikit/
I'd written something very similar before I stumbled on this. You can  
use different nibs for each view, and once you master bindings across  
different nibs, it seems to me to be perfect MVC.


On Aug 27, 2009, at 8:55 AM, Support wrote:

I'm writing an application which has one window, with an NSTableView  
and a WebView in it.  The NSTableView will contain a list of URLs  
and site descriptions and the WebView will display the URL when it's  
clicked on in the NSTableView.  So far, so simple - especially if  
the NSTableView and WebView are in the same object.


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'd be most grateful for any enlightenment.

___

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/bryscomat%40gmail.com

This email sent to brysco...@gmail.com


___

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