ストーリーボードの単純なボタンを使用して、別のクラスからメソッドを呼び出そうとしています。ここに私のファイルがあります:
ViewController.m
// ViewController.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "PrintHello.h"
@interface ViewController : UIViewController <NSObject>{
PrintHello *printMessage;
}
@property (nonatomic, retain) PrintHello *printMessage;
@end
ViewController.m
// ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize printMessage;
- (void)viewDidLoad{
[super viewDidLoad];
NSLog(@"ViewDidLoad loaded");
}
- (IBAction)Button01:(id)sender{
self.printMessage = [[PrintHello alloc] init]; // EDIT: THIS LINE WAS MISSING NOW IT WORKS
[self.printMessage Print];
NSLog(@"Button01 Pressed");
}
@end
PrintHello.h
// PrintHello.h
#import <Foundation/Foundation.h>
@interface PrintHello : NSObject
-(void) Print;
@end
PrintHello.m
// PrintHello.m
#import "PrintHello.h"
@implementation PrintHello
-(void)Print{ NSLog(@"Printed");}
@end
また、storyBoard には、Viecontroller にリンクされた Button01 があります。ログから私はそれを知っています:
viewDidLoad がロードされ、ボタンが押されるとボタンが押されます:)しかし、メソッド Print は呼び出されませんか?
私はどこで間違っていますか?