下面的代码拒绝编译,因为方法:“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{}
答案 0 :(得分:2)
将目标从'self'更改为[MyClass class],其中MyClass是您班级的名称。
答案 1 :(得分: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); }
答案 2 :(得分:1)
嘿。你能检查一下你拨打的方法是scheduledTimerWithTimeInterval
吗?您的代码调用了scheduledTimerWithInterval
...错过了Time
部分