在ViewController的头部声明对象

时间:2015-11-08 14:41:28

标签: ios objective-c uiviewcontroller

在下面的代码中,我试图在ViewController.h的头部声明一个Player类的对象,并在ViewController.m中调用它的方法。问题是没有任何反应,并且没有调用方法。有人可以帮我解决这个问题吗

ViewController.h

#import "Player.h"
@interface ViewController : UIViewController{
    __weak IBOutlet Player *player; 
}

ViewController.m

-(void)update
{
    if([player collision] == TRUE)
    {
        [player nextHead];
        [player drawTrail:@"green"];
    }

}

1 个答案:

答案 0 :(得分:0)

我对你的设置有点不清楚,但是为了在黑暗中拍摄,你是否想要完成这样的事情:

@interface ViewController: UIViewController

@property (nonatomic, strong) IBOutlet Player *player;
@property (nonatomic, strong) NSTimer *updateTimer;

@end
@implementation

- (void)viewDidLoad {
     // fire time 10 times a second to call update
    _updateTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 
                            target:self 
                            selector:@selector(update) 
                            userInfo:nil 
                            repeats:YES];
}

-(void)update
{
    if([player collision] == TRUE)
    {
        [player nextHead];
        [player drawTrail:@"green"];
    }

}