我想维护数据封装,并NSObject
从我的ViewController.m
.
我的 Objective-C 工作正常,我的类在ViewController
's中实例化viewDidLoad
,我可以通过 my 的方法设置、获取和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);
}