• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Accessing Variables from Multiple NIBs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Accessing Variables from Multiple NIBs


  • Subject: Accessing Variables from Multiple NIBs
  • From: Jonathan Buys <email@hidden>
  • Date: Sat, 16 Jan 2010 18:45:20 -0600

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

  • Follow-Ups:
    • Re: Accessing Variables from Multiple NIBs
      • From: Jon Buys <email@hidden>
  • Prev by Date: Re: needing help w/ asynchronous message problem, using YAMessageQueue
  • Next by Date: Re: NSTextField sendActionOn:
  • Previous by thread: Re: NSDatePicker 24 hour clock (Daniel Wambold)
  • Next by thread: Re: Accessing Variables from Multiple NIBs
  • Index(es):
    • Date
    • Thread