0

Hey I'm new to Xcode so maybe this has a very easy fix and in that case I'm sorry but I've tried everything and looking online and nothing has worked so far. Basically I created a continueButton to transition to the next scene in the app once the level has been completed. Heres what its code looks like

UIButton *continueButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
continueButton.frame = CGRectMake(120, 150, 80, 44);
[continueButton setTitle:@"Continue" forState:UIControlStateNormal];
[continueButton addTarget:self action:@selector(SKTransition:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:continueButton];

Then I defined what happens when I click on the continueButton as this.

-(void)buttonPressed:(UIButton *)sender
{
    SKAction *levelChange = [SKAction runBlock:^{

        SKTransition *doors = [SKTransition
                               doorsOpenVerticalWithDuration:2];

        SKScene *Level2Scene  = [[Transition2Scene alloc]
                                 initWithSize:self.size];

        [self.view presentScene:Level2Scene transition:doors];
        [self runAction:levelChange];
    }];
}

However whenever I run that app and click on the continueButton I get this error.

2014-07-27 21:14:14.225 MazeGame[40846:60b] -[Level1Scene SKTransition:]: unrecognized selector sent to instance 0x14158670 (lldb)

at this point in the code.

#import <UIKit/UIKit.h>
#import "SpriteAppDelegate.h"

int main(int argc, char * argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([SpriteAppDelegate class]));
    }
}

I don't exactly know what went wrong or what I should do and would really appreciate some help/advice thanks!

jtbandes
  • 115,675
  • 35
  • 233
  • 266
alec6134
  • 3
  • 2
  • What it's saying is that you did a call of the method "SKTransition" against an object of class "Level1Scene", and that class does not have a method by that name. If you look at the exception trace (see [here](http://stackoverflow.com/q/8100054/581994)) then you will see exactly where this call occurred. Basically it means that you got the wrong object in a pointer somehow. – Hot Licks Jul 28 '14 at 02:44
  • 1
    (Note that if the compiler was screaming at you about not finding an interface that contained the method "SKTransition" this is what it was trying to warn you about.) – Hot Licks Jul 28 '14 at 02:46
  • add an exception breakpoint to see the exact line of code where the error occurs, without this breakpoint all errors will point at the line in main() – CodeSmile Jul 28 '14 at 08:11

1 Answers1

1

My guess is that the issue is this line:

[continueButton addTarget:self action:@selector(SKTransition:) forControlEvents:UIControlEventTouchUpInside];

It should be:

[continueButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
NeverHopeless
  • 11,077
  • 4
  • 35
  • 56
  • Hey thanks for the help! That worked sorry that was a really obvious fix I feel dumb but I appreciate the help – alec6134 Jul 28 '14 at 13:34