tags:

views:

21

answers:

2

I have put a button over a toolbar.But when i press that button,my selector is not called and application crashes giving following error

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[ChatViewController changeButtonImage]: unrecognized selector sent to instance 0x119570'

here is my code..

UIToolbar *toolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(5,0,310,44)];
UIBarButtonItem *changeImagebtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemOrganize
                                                                                     target:self
                                                                                     action:@selector(changeButtonImage)];




    UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                              target:nil
                                                                              action:nil];

    UIBarButtonItem *textField = [[UIBarButtonItem alloc] initWithCustomView:peerName];

    NSArray *items = [NSArray arrayWithObjects:textField,flexItem,flexItem,changeImagebtn,nil];
    [toolBar setItems:items animated:NO];
[self.view addSubview:toolBar];

My action block is ----

-(void)changeButtonImage:(id)sender
{
    UIImagePickerController *pic=[[UIImagePickerController alloc] init];
    pick=pic;
    pick.delegate=self;

    pick.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:pick animated:YES];
}

where am i wrong?Please suggest me...

+1  A: 

Instead of

action:@selector(changeButtonImage)

it must be:

action:@selector(changeButtonImage:)
Ole Begemann
that really was the case !Thanks..
Ajayvictor007
A: 

I would have said that instead of:

-(void)changeButtonImage:(id)sender {}

You would use:

-(void)changeButtonImage {}

That works perfectly fine for me in my apps and you're not using the sender in your method code anyway.

EDIT : of course remember that if you were going to do this then also amend your definition in the header file.

Louis Russell