Re: Two controllers in a window, how do I get one to run a function in another?
Re: Two controllers in a window, how do I get one to run a function in another?
- Subject: Re: Two controllers in a window, how do I get one to run a function in another?
- From: BareFeet <email@hidden>
- Date: Tue, 1 Sep 2009 16:13:55 +1000
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 (email@hidden)
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:
This email sent to email@hidden