PrefMySpotsViewCtrl.h
@class Location;
@interface PrefMySpotsViewCtrl : NSViewController
{
NSTextField *locationSearchInput;
NSString * enteredLocation;
Location *l;
}
@property (nonatomic, retain) IBOutlet NSTextField *locationSearchInput;
@property (nonatomic, retain) NSString *enteredLocation;
PrefMySpotsViewCtrl.m
#import "Location.h"
- (void) controlTextDidChange:(NSNotification *)aNotification
{
enteredLocation = [locationSearchInput stringValue];
NSLog(@"in class:%@", enteredLocation);
[l searchLocation];
}
Location.h
@class PrefMySpotsViewCtrl;
@interface Location : NSObject
{
PrefMySpotsViewCtrl *p;
}
- (void) searchLocation;
Location.m
#import "Location.h"
#import "PrefMySpotsViewCtrl.h"
@implementation Location
- (void) searchLocation
{
NSLog(@"out of class: %@", [p enteredLocation]);
}
User inputs a into locationSearchInput and here is the output
2012-09-30 10:18:12.915 MyApp[839:303] in class:
2012-09-30 10:18:12.917 MyApp[839:303] in class:a
searchLocation method is never executed.
If I do l = [[Location alloc] init]; , then searchLocation is executed but the output is null
2012-09-30 10:28:46.928 MyApp[880:303] in class:
2012-09-30 10:28:46.929 MyApp[880:303] out of class: (null)
2012-09-30 10:28:46.930 MyApp[880:303] in class:a
2012-09-30 10:28:46.931 MyApp[880:303] out of class: (null)
Any idea?
Thanks?
But, the question is : have you assigned a valid instance of the controller(PrefMySpotsViewCtrl) to the location object ?
I mean :
Keep in mind that is better to declare the PrefMySpotsViewCtrl as a property in the Location declaration, something like the following :
And then assign it using the property setter :
EDIT
Since from the comments below seems that the OP didn’t understand the logic, i post a simple example to let him understand better :
1) ClassA declaration :
2) ClassB declaration:
3) Usage :