如果您能找出所有 [self doesIntersect] 行和所有 [self doesIntersectWithCheckpoint],那么我想知道该代码有什么问题。它工作了几天,然后xcode开始给我这个错误消息“找不到实例方法'-doesIntersect'(返回类型默认为“id”)”请帮助!
#import "SecondLevelViewController.h"
@interface SecondLevelViewController ()
@end
@implementation SecondLevelViewController
float dx, dy;
int score = 0;
- (void)moving{
user.center = CGPointMake(user.center.x + dx, user.center.y + dy);
if ([self doesIntersect]){
user.center = CGPointMake(user.center.x - dx, user.center.y - dy);
dx = 0;
dy = 0;
}
}
- (IBAction)goUp:(id)sender{
dx = 0;
dy = -1;
}
- (IBAction)goDown:(id)sender{
dx = 0;
dy = 1;
}
- (IBAction)goright:(id)sender{
dx = 1;
dy = 0;
}
- (IBAction)goLeft:(id)sender{
dx = -1;
dy = 0;
}
-(BOOL)doesIntersect {
[self intersectWithCheckpoint];
for (int i = 0; i < [blockArray count]; i++) {
UIImageView *blk = [blockArray objectAtIndex:i];
if (CGRectIntersectsRect(user.frame, blk.frame)) {
return YES;
}
}
return NO;
}
- (void)setScore{
score = (score + 1);
scoreCount.text = [NSString stringWithFormat:@"%d", score];
}
- (IBAction)resetAnimation:(id)sender{
user.center = CGPointMake(460, 150);
winLabel.text = @"";
goToNextLevel.hidden = YES;
}
- (void)intersectWithCheckpoint {
if (CGRectIntersectsRect(user.frame, checkpoint.frame)){
dx = 0;
dy = 0;
goToNextLevel.hidden = NO;
winLabel.text = @"YOU WIN!";
[scoreTimer invalidate];
}
}
- (void) viewDidLoad
{
goToNextLevel.hidden = YES;
//blocks
[super viewDidLoad];
score = 0;
mainTimer = [NSTimer scheduledTimerWithTimeInterval : (0.01) target : self selector : @selector(moving) userInfo : nil repeats : YES];
blockArray = [[NSArray alloc] initWithObjects:block, block1, block2, block3, block4, block5, block6, block7, block8, block9, block10, block11, block12, block13, block14, block15, block16, block17, block18, block19, block20, block21, block22, nil];
scoreTimer = [NSTimer scheduledTimerWithTimeInterval:(1.00) target:self selector:@selector(setScore) userInfo:nil repeats:YES];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end