MainController.h
#import <Cocoa/Cocoa.h>
@interface MainController : NSWindowController {
NSWindowController *sc;
IBOutlet NSTextField *txt1;
}
-(IBAction)executeButtonClick:(id)sender;
-(void)setTxt1Text:(NSString *)txt;
@end
MainController.m
#import "MainController.h"
#import "SecondController.h"
@implementation MainController
-(void)awakeFromNib
{
sc = nil;
}
-(IBAction)executeButtonClick:(id)sender;
{
if (sc == nil)
{
sc = [[SecondController alloc] initWithMController:self];
}
[sc showWindow:self];
[[sc window] makeKeyAndOrderFront:sender];
}
-(void)setTxt1Text:(NSString *)txt;
{
[txt1 setStringValue:txt];
}
@end
SecondController.h
#import <Cocoa/Cocoa.h>
@interface SecondController : NSWindowController {
NSWindowController *mController;
}
-(id)initWithMController:(NSWindowController *)mctrl;
-(IBAction)testButtonClick:(id)sender;
@end
Вот проблема:
SecondController.m
#import "SecondController.h"
@implementation SecondController
-(id)initWithMController:(NSWindowController *)mctrl;
{
self = [super initWithWindowNibName:@"SecondWindow"];
mController = mctrl;
NSLog(@"%@",mController);
return self;
}
-(IBAction)testButtonClick:(id)sender;
{
NSLog(@"%@",mController);
[mController setTxt1Text:@"Test Success"];
}
@end
Журналы:
2011-05-09 15:41:10.337 MultiWindow[4334:a0f] <MainController: 0x1005295b0>
2011-05-09 15:41:11.336 MultiWindow[4334:a0f] (null)
Почему mController стал нулевым?Кто-нибудь может помочь?
Спасибо