Hello,

I have an AppController that looks like this:

AppController.h:
#import <Cocoa/Cocoa.h>
@class PostController;

@interface AppController : NSObject 
{
        PostController *postController;
        NSString *theString;
}

- (IBAction)setString:(id)sender;
- (IBAction)viewString:(id)sender;

- (void)processString;

@end

AppController.m:

#import "AppController.h"
#import "PostController.h"

@implementation AppController


- (IBAction)setString:(id)sender
{
        // Is postController nil?
        if (!postController) {
                //      NSLog(@"Post Controller was nil.");
                postController = [[PostController alloc] init];
        }
        
        //      NSLog(@"Showing %@", postController);
        [postController showWindow:self];
                
        theString = @"The String";
        
        NSLog(@"Current Selected Site: %@", theString); 
        [self processString];
}

- (IBAction)viewString:(id)sender
{
        NSLog(@"viewString Method: %@", theString);
        [self processString];
}

- (void)processString
{
        NSLog(@"processString Method: %@", theString);
}


@end

I have two XIB files, MainMenu and NewPost.  I've dragged an NSObject into each 
XIB, and set it's class to AppController.  In MainMenu, I have two buttons, one 
bound to the setString action, and one set to the processString action.  In 
MainMenu XIB, I can see theString in the NSLog output.  In the NewPost XIB, I 
have one button bound to the processString method, but from this XIB, every 
time I run the processString method, theString is  null.  

How can I define a variable (like NSString) in one XIB, and be able to access 
it from methods triggered from another XIB?

I've got a simple Xcode project that shows this problem, if it would help with 
explaining it.

Thanks,

Jon

PS.  Here is the PostController too, just in case:

#import <Cocoa/Cocoa.h>


@interface PostController : NSWindowController 
{
}

@end


#import "PostController.h"
#import "AppController.h"


@implementation PostController

- (id)init
{
        if (![super initWithWindowNibName:@"NewPost"])
                return nil;
        
        return self;
}


- (void)windowDidLoad
{
        NSLog(@"Nib file is loaded!");
}

@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

Reply via email to