PDA

View Full Version : My Button crashes the App




mistergreen2011
Apr 11, 2011, 09:58 AM
I create a button at runtime. The button appears but crashes the app with an NSException error when I click on it. I don't see what the issue is. I need a pair of new eyes. Thanks.


-(void)setupInterface {
//button
CGRect frame = CGRectMake(100.0, 100.0, 70.0, 20.0);

UIButton *btn = [[UIButton alloc] initWithFrame:frame];

[btn setTitle:@"Button" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlEventTouchDown];
btn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[btn addTarget:self action:@selector(doneAction:) forControlEvents:UIControlEventTouchUpInside];

[self addSubview:btn];
[btn autorelease];

}


- (void)doneButton:(id)sender {
//problem here*
//[self removeFromSuperview];
NSLog(@"press");
}



huskerchad
Apr 11, 2011, 10:02 AM
Your action maps to selector doneAction: and not to the method body you posted for doneButton:

Is the exception that your target does not respond to the selector?

mistergreen2011
Apr 11, 2011, 10:12 AM
thanks, you caught it...

It should be @selector(doneButton:)

dejo
Apr 11, 2011, 10:17 AM
In the future, please post any actual error messages / warnings (copy-and-paste, if necessary). Otherwise, you are just being disrespectful of those you are seeking help from. Thank you for your consideration.

mistergreen2011
Apr 11, 2011, 11:26 AM
As mentioned, all I got was an NSException error in the message and the emulator crashing.
I'll consider what you said but have no idea what you mean by disrespecting people which is 100% not my intent.

amorya
Apr 12, 2011, 05:53 AM
As mentioned, all I got was an NSException error in the message and the emulator crashing.
I'll consider what you said but have no idea what you mean by disrespecting people which is 100% not my intent.

I think he means you should copy and paste the specific NSException that you got. For example, it might say something like this:

2011-04-12 10:23:04.488 National Rail[1109:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'

That's an NSException, but it gives more detail to post the error message.