Frage

I am creating an app in Objective C, and I am receiving a runtime error when I press the button in my app. This is the code that creates the buttons. Yes I do have to use the coded version, before anyone asks.

extend = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //3
[extend setFrame:CGRectMake(100, 50, 75, 50 )];
[extend setTitle:@"Extend" forState:UIControlStateNormal];
[extend addTarget:self action:@selector(extendPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:extend];
[self.view bringSubviewToFront:extend];

retract = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //3
[retract setFrame:CGRectMake(100, 110, 75, 50 )];
[retract setTitle:@"Retract" forState:UIControlStateNormal];
[extend addTarget:self action:@selector(retractPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:retract];
[self.view bringSubviewToFront:retract];

And here are the actions.

- (IBAction)extendPressed:(UIButton *)sender{

    NSLog(@"Extend");

}

- (IBAction)retractPressedPressed:(UIButton *)sender{

    NSLog(@"Retract");

}

When I press the Retract Button, nothing happens, but when I press the Extend button, the app crashes and this shows up in the debug console:

2013-07-31 16:57:49.479 Drive 3.0[1557:907] Extend 2013-07-31 16:57:49.482 Drive 3.0[1557:907] -[driveViewController retractPressed:]: unrecognized selector sent to instance 0x1f564730 2013-07-31 16:57:49.483 Drive 3.0[1557:907] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[driveViewController retractPressed:]: unrecognized selector sent to instance 0x1f564730' * First throw call stack: (0x33c9e3e7 0x3b999963 0x33ca1f31 0x33ca064d 0x33bf8208 0x35b98087 0x35b9803b 0x35b98015 0x35b978cb 0x35b97db9 0x35ac05f9 0x35aad8e1 0x35aad1ef 0x377c55f7 0x377c5227 0x33c733e7 0x33c7338b 0x33c7220f 0x33be523d 0x33be50c9 0x377c433b 0x35b012b9 0x1a229 0x19f88) libc++abi.dylib: terminate called throwing an exception

Thank you in advance to anyone able to help and tell me what I am doing wrong.

War es hilfreich?

Lösung

You have a typo in your method name:

retractPressedPressed

should just be:

retractPressed
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top