My Button crashes the App

Discussion in 'iOS Programming' started by mistergreen2011, Apr 11, 2011.

  1. mistergreen2011
    Expand Collapse
    macrumors member

    Mar 23, 2011
    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 {
        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];
  2. huskerchad
    Expand Collapse
    macrumors regular

    Jul 17, 2002
    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?
  3. mistergreen2011
    Expand Collapse
    thread starter macrumors member

    Mar 23, 2011
    thanks, you caught it...

    It should be @selector(doneButton:)
  4. dejo
    Expand Collapse


    Staff Member

    Sep 2, 2004
    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.
  5. mistergreen2011
    Expand Collapse
    thread starter macrumors member

    Mar 23, 2011
    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.
  6. amorya
    Expand Collapse
    macrumors 6502

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

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

Share This Page