1

So this is what i have. I have created a button and set it to an action but every time i click the button it crashes the program. Why wont my button work? Thanks in advance.

UIButton *currentGamesButton = [UIButton buttonWithType:UIButtonTypeCustom];
currentGamesButton.frame = CGRectMake(124,18,72,65);
[currentGamesButton addTarget:self
                       action:@selector(goToCurrentGamesViewController:)
             forControlEvents:UIControlEventTouchDown];
UIImage *currentGamesPNG = [UIImage imageNamed:@"CurrentGamesHighlightedState.png"];
[currentGamesButton setBackgroundImage:currentGamesPNG forState:UIControlStateNormal];
[self.view addSubview:currentGamesButton];
GingerHead
  • 8,130
  • 15
  • 59
  • 93
nfoggia
  • 513
  • 1
  • 8
  • 28

1 Answers1

4

If the method for goToCurrentGamesViewController takes no parameters, change this line:

[currentGamesButton addTarget:self
                   action:@selector(goToCurrentGamesViewController:)

to:

[currentGamesButton addTarget:self
                   action:@selector(goToCurrentGamesViewController)

(remove the colon : from the method in the selector)

Matisse VerDuyn
  • 1,148
  • 15
  • 40