Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios5 如何将独立类文件(.m)对象的连接插座添加到ViewController';主配电盘_Ios5_Xcode4.2 - Fatal编程技术网

Ios5 如何将独立类文件(.m)对象的连接插座添加到ViewController';主配电盘

Ios5 如何将独立类文件(.m)对象的连接插座添加到ViewController';主配电盘,ios5,xcode4.2,Ios5,Xcode4.2,我想维护数据封装,并已将NSObject类(.h和.m文件)从我的ViewController.m中分离出来 当我的类在ViewController的viewDidLoad中实例化时,Objective-C可以正常工作,我可以通过NSObject的方法设置、获取和NSLog私有值 我不能做的是在MainStoryboard中分配连接插座和接收的操作。我的IBOutlets(aui标签和ui按钮)未显示在连接检查器中。但是,我的ViewController的[hm]文件中有许多对象,我可以设置插座

我想维护数据封装,并已将
NSObject
类(.h和.m文件)从我的
ViewController.m
中分离出来

当我的类在
ViewController
viewDidLoad
中实例化时,Objective-C可以正常工作,我可以通过
NSObject
的方法设置、获取和
NSLog
私有值

我不能做的是在
MainStoryboard
中分配连接插座和接收的操作。我的
IBOutlets
(a
ui标签
ui按钮
)未显示在连接检查器中。但是,我的
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);
}
//GameTimer.h
#进口
@接口游戏计时器:NSObject{
UILabel*游戏时间标签;
NSTimer*游戏计时器;
未签名的整型gameTimerTicks;
}
@属性未签名的整数gameTimerTicks;
@属性(非原子,保留)IBUILabel*gameTimerLabel;
@属性(非原子,保留)IBUIButton*startButton;
//实例化计时器
-(iAction)启动时按下:(id)发送方;
//更新gameTimerLabel,向用户显示新值
-(无效)游戏时间展示;
//计时器的选择器func,管理所有计时器的计时计数
-(无效)gameTimerEvent;
@结束
//FirstViewController.m
#导入“FirstViewController.h”
#导入“GameTimer.h”
@接口FirstViewController()
@结束
@FirstViewController的实现
游戏计时器*我的游戏时钟;
-(无效)viewDidLoad
{
[超级视图下载];
myGameClock=[[GameTimer alloc]init];
[myGameClock setGameTimerTicks:33*10];
[myGameClock gameTimerShow];
无符号长myticks=myGameClock.gameTimerTicks;
NSLog(@“Ticks=%lu”,myticks);
}

我认为您可能混淆了封装和控制器的角色。由于Cocoa Touch框架是一个模型视图控制器,因此控制器是位于视图的用户解释与模型的数据和业务规则之间的“管理者”。因此,必须将IBOutlets和IBActions放入UIViewController子类中

将计时器构建到单独的类中。然后,计时器将被视为模型的一部分,其他控制器或模型的其他对象可以根据需要实例化。让您的控制器实例化一个“计时器”。然后使用控制器管理“计时器”操作。如果需要显示经过的时间,那么控制器应该从“Timer”对象获取经过的时间,并将其放入适当的控件中。如果需要在“计时器”中设置时间长度,那么控制器将从视图控件中获取值并将其放入“计时器”中

希望这有帮助