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];
}
位置.h
@class PrefMySpotsViewCtrl;
@interface Location : NSObject
{
PrefMySpotsViewCtrl *p;
}
- (void) searchLocation;
位置.m
#import "Location.h"
#import "PrefMySpotsViewCtrl.h"
@implementation Location
- (void) searchLocation
{
NSLog(@"out of class: %@", [p enteredLocation]);
}
用户输入 a locationSearchInput
,这是输出
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
方法永远不会执行。
如果我这样做l = [[Location alloc] init];
,则searchLocation
执行但输出为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)
任何的想法?
谢谢?