Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mistergreen2011

macrumors member
Original poster
Mar 23, 2011
36
0
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.

Code:
-(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];
    
}

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

huskerchad

macrumors regular
Jul 17, 2002
246
0
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?
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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

macrumors member
Original poster
Mar 23, 2011
36
0
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

macrumors 6502
Jun 17, 2007
252
7
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.