开发者

Call function from another controller, why doesn't works?

开发者 https://www.devze.com 2023-02-23 01:58 出处:网络
AppController.h #import <Cocoa/Cocoa.h> #import \"DebugController.h\" @class DebugController; @interface AppControlle开发者_如何转开发r : NSObject {

AppController.h

#import <Cocoa/Cocoa.h>
#import "DebugController.h"

@class DebugController;
@interface AppControlle开发者_如何转开发r : NSObject {
    DebugController * controller;
}

@end

AppController.m

#import "AppController.h"

@implementation AppController

-(void)awakeFromNib {
    NSLog(@"awake");
    [controller sendDebug];

}
@end

DebugController.h

#import <Cocoa/Cocoa.h>
#import "AppController.h"

@interface DebugController : NSObject {

}
- (void)sendDebug;
@end

DebugController.m

#import "DebugController.h"

@implementation DebugController

- (void)sendDebug {
    NSLog(@"debug"); // no logs.
}

@end


You don't initialize the debug controller (controller), which means its initially nil (as its an instance variable). Sending a message to nil is legal, but nothing happens. You have to initialize your debug controller ivar first.

0

精彩评论

暂无评论...
验证码 换一张
取 消