Jesse Durham
Jesse Durham

Reputation: 285

UIButton selector is throwing 'unrecognized selector' even though selector exists

I am creating 2 buttons programmatically in my view. Both selector methods exist but it is still throwing 'unrecognized selector' errors. I read something about checking for zombies. But I activiated it (xcode 4.2) and didn't see anything about any zombies. Here is the code..

- (void)viewDidLoad
{

    for(int i = 0; i < [list count]; i++){  

     ... if statement checks to add text fields
    }

     UIButton *submit = [UIButton buttonWithType:UIButtonTypeRoundedRect];
     [submit addTarget:self action:@selector(submission:)
     forControlEvents:UIControlEventTouchUpInside];
     [submit setTitle:@"Submit" forState:UIControlStateNormal];
     submit.frame = CGRectMake(x+ 170.0, y, 72, 37);

    UIButton *addition = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [addition addTarget:self action:@selector(addition:)
    forControlEvents:UIControlEventTouchUpInside];
    [addition setTitle:@"Additional Mission" forState:UIControlStateNormal];
    addition.frame = CGRectMake(x, y, 140, 37);

    y = y+90;
   [inputsView addSubview:submit];
   [inputsView addSubview:addition];
   [inputsView setScrollEnabled:YES];
   [inputsView setContentSize:CGSizeMake(320, y)]; 


}

 - (void)submission{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Submission Complete" message:@"Submission"
                                               delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alert show];
}

 -(void)addition{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Creating Additional Mission" message:@"Additional Mission"
                                               delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alert show];
}

One thing to note.. inputsView is a UIScrollView that is inside my viewcontroller.

Thanks in advance.

Upvotes: 1

Views: 227

Answers (2)

Shubhank
Shubhank

Reputation: 21805

[addition addTarget:self action:@selector(addition:)

in this line you are saying that your selector @selector(addition:) expects a parameter that is a colon after addition but in your real method

 -(void)addition{

there is no parameter after addition ..that is why there is a crash..remove the colon in both submission and addition and you will be good to go.

Upvotes: 1

wattson12
wattson12

Reputation: 11174

remove the colon from the selector methods

[submit addTarget:self action:@selector(submission)

[addition addTarget:self action:@selector(addition)

the colon tells the selector that this method takes arguments, yours do not so the colon should not be part of the selector

Upvotes: 5

Related Questions