我正在尝试为 OSX Lion 构建一个 Cocoa 应用程序。我的 AppController 代码中有这一行:
self.viewController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil appController:self];
[_view addSubview:[_viewController view]];
[[_viewController view] setFrame:[_view bounds]];
LoginViewController 看起来像这样:
@implementation LoginViewController
@synthesize appController = _appController;
- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil appController:(AppController *)appController {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[self setAppController:appController];
NSLog(@"Appcontroller init: %@", _appController);
}
return self;
}
- (IBAction)login:(id)sender {
NSLog(@"Appcontroller login: %@", _appController);
}
登录方法与单击按钮相关联。
日志:
2012-05-23 12:45:49.574 QBLoader[3241:503] Appcontroller init: <AppController: 0x7fe2ab210440>
2012-05-23 12:45:52.085 QBLoader[3241:503] Appcontroller login: (null)
为什么第二个日志行为空?