开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜