1

以下代码拒绝编译,因为方法:“FollowPlayer”是具有类级别访问权限的类方法。如何正确允许 NSTimer 调用 +(void)FollowPlayer?

- (void)awakeFromNib{zombie_size=4; timer=[NSTimer scheduledTimerWithInterval: 1.0 target:self selector:@selector(FollowPlayer) userInfo:nil repeats: NO];}

+ (void)FollowPlayer: NSTimer{}
4

3 回答 3

2

将目标从“self”更改为 [MyClass class],其中 MyClass 是您的班级名称。

于 2011-05-17T18:10:33.333 回答
1

您确定这不仅仅是语法错误吗?你能做这个吗?

- (void)awakeFromNib{zombie_size=4; timer=[NSTimer scheduledTimerWithInterval: 1.0 target:self selector:@selector(FollowPlayer:) userInfo:nil repeats: NO];}
+ (void)FollowPlayer:(id)userInfo { NSLog(@"Timer called with user info %@", userInfo); }
于 2011-05-17T18:19:07.577 回答
1

嘿。你能检查你正在调用的方法是scheduledTimerWithTimeInterval吗?您的代码调用scheduledTimerWithInterval...缺少Time部分

于 2011-05-17T18:43:27.087 回答