【发布时间】:2013-04-02 05:50:36
【问题描述】:
在我的代码中,两个 -(void) 语句都出现“missing context for method declaration”错误,我无法找出原因。
这是我的代码:
- (void)onTimer {
[self checkCollision];
bad.center = CGPointMake(bad.center.x+pos.x,bad.center.y+pos.y);
if(bad.center.x >320 || bad.center.x<0)
pos.x = -pos.x;
if(bad.center.y >480 || bad.center.y<0)
pos.y = -pos.y;
}
- (void) checkCollision {
if (CGRectIntersectsRect(good.frame,bad.frame)) {
[startButton setHidden:NO];
[timer invalidate];
CGRect frame = [good frame];
frame.origin.x = 132.0;
frame.origin.y = 332.0;
[good setFrame:frame];
CGRect frame2 = [good frame];
frame2.origin.x = 125.0;
frame2.origin.y = 70.0;
[bad setFrame:frame2];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Your not fast enough!" message:@"Try again!" delegate:nil cancelButtonTitle:@"Dismiss"otherButtonTitles:nil];
[alert show];
[alert release];
}
@end
【问题讨论】:
-
我们刚刚回答了您的这个问题,就像半小时前一样。不要告诉我你不能从中推断出这个问题的解决方案,只是这次缺少的是
@implementation MyClassName。不要来这里要求我们解决你每三十分钟遇到的每一个语法错误,所以不是为了那个目的。努力学习该语言的基础知识。 -
我讨厌在这里发布我的诚实问题而受到这样的抨击,下次我会在其他地方问,给您带来的不便很抱歉
-
另外,我敦促您遵循我从其他问题中提出的简单建议,即找到一些工作代码并将您自己的代码与它进行比较。您可能会找到解决方案,并学到一些东西。如果您尝试这样做,但即使在搜索之后仍然无法得到它,那可能意味着您有一个很好的候选人来回答一个新问题。但现在看起来你只是在向全世界宣布你不想做任何事情来帮助自己,这就是你被否决的原因。
-
首先,也可能是最后一点,@implementation MyClassName 部分实际上是不需要的,你错了。我有一个类似的问题,我有两个 .h 文件。其中一个提出了 OP 询问的错误。另一个没有。一定是其他问题。
标签: objective-c