My Button crashes the App

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

  1. macrumors member

    Joined:
    Mar 23, 2011
    #1
    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");
    }
     
  2. macrumors regular

    Joined:
    Jul 17, 2002
    #2
    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. thread starter macrumors member

    Joined:
    Mar 23, 2011
    #3
    thanks, you caught it...

    It should be @selector(doneButton:)
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    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. thread starter macrumors member

    Joined:
    Mar 23, 2011
    #5
    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. macrumors 6502

    Joined:
    Jun 17, 2007
    #6
    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