データのカプセル化を維持したいので、NSObject
クラス(.hおよび.mファイル)を。から分離しましたViewController.m
。
私はObjective-Cを正しく機能させており、クラスは'sでインスタンス化されておりViewController
、 'sメソッドを介してプライベート値をviewDidLoad
設定、取得、および取得できます。NSLog
NSObject
私ができないことはMainStoryboard
、接続アウトレットと受信アクションを割り当てることです。私のIBOutlets
(aUILabel
とUIButton
)が接続インスペクターに表示されません。ただし、ViewController
アウトレット接続を設定できるオブジェクトが。[hm]ファイルに多数あります。ストーリーボードツールで表示できないのは、この新しいファイルのオブジェクトだけです。
私は何が間違っているのですか?
// GameTimer.h
#import <Foundation/Foundation.h>
@interface GameTimer : NSObject {
UILabel *gameTimerLabel;
NSTimer *gameTimer;
unsigned int gameTimerTicks;
}
@property unsigned int gameTimerTicks;
@property (nonatomic, retain) IBOutlet UILabel *gameTimerLabel;
@property (nonatomic, retain) IBOutlet UIButton *startButton;
// instantiate the timer
- (IBAction)onStartPressed:(id)sender;
// Update the gameTimerLabel, show new value to user
- (void)gameTimerShow;
// selector func for our timer, manages the tick count for all our timers
- (void)gameTimerEvent;
@end
// FirstViewController.m
#import "FirstViewController.h"
#import "GameTimer.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
GameTimer *myGameClock;
- (void)viewDidLoad
{
[super viewDidLoad];
myGameClock = [[GameTimer alloc] init];
[myGameClock setGameTimerTicks:33*10];
[myGameClock gameTimerShow];
unsigned long myticks = myGameClock.gameTimerTicks;
NSLog(@"Ticks=%lu", myticks);
}