这是我的.h视图控制器文件:
#import <UIKit/UIKit.h>
@interface ZKGameController : UIViewController
{
IBOutlet UIImageView *PlayerSprite;
IBOutlet UIButton *rightButton;
IBOutlet UIButton *leftButton;
NSTimer *animationTimer;
}
[rightButton addTarget:self action:@selector(startLeftAnimation) forControlEvents:UIControlEventTouchDown];
[rightButton addTarget:self action:@selector(stopAnimation) forControlEvents:UIControlEventTouchUpInside];
[rightButton addTarget:self action:@selector(stopAnimation) forControlEvents:UIControlEventTouchUpOutside];
[leftButton addTarget:self action:@selector(startLeftAnimation) forControlEvents:UIControlEventTouchDown];
[leftButton addTarget:self action:@selector(stopAnimation) forControlEvents:UIControlEventTouchUpInside];
[leftButton addTarget:self action:@selector(stopAnimation) forControlEvents:UIControlEventTouchUpOutside];
- (void)stopAnimation;
- (void)frontBarrelAnimation;
- (void)barrelStartDown;
- (void)startLeftAnimation;
- (void)startRightAnimation;
- (void)animateLeft;
- (void)animateRight;
@end
它给了我关于“leftButton addTarget:self ...”的错误消息,等等等等等等。 我搜索了为什么,我找不到任何理由,但它说“预期的标识符或'(',使用未声明的标识符”self“和”leftButton“和右键相同的东西。
如果有帮助,这是我的.m文件: #import“ZKGameController.h”
@interface ZKGameController ()
@end
@implementation ZKGameController
- (void)startLeftAnimation
{
animationTimer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(animateLeft) userInfo:nil repeats:YES];
}
- (void)startRightAnimation
{
animationTimer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(animateRight) userInfo:nil repeats:YES];
}
- (void)stopAnimation
{
if(animationTimer != nil)
{
[animationTimer invalidate];
animationTimer = nil;
}
}
- (void)animateLeft
{
PlayerSprite.center = CGPointMake(PlayerSprite.center.x - 1, PlayerSprite.center.y);
}
- (void)animateRight
{
PlayerSprite.center = CGPointMake(PlayerSprite.center.x + 1, PlayerSprite.center.y);
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
我已将所有图片视图和按钮与正确的内容相关联,但它为我提供了这些消息。如果您有任何建议请帮助。
答案 0 :(得分:0)
剪切并粘贴,之后将目标调用添加到viewDidLoad方法 [super viewDidLoad];在.m文件