unrecognized selector sent to instance error on button added to toolbar of subclassed ttphotoviewcontroller

StackOverflow https://stackoverflow.com/questions/11826817

Domanda

I have subclass TTphotoviewcontroller and added a button for saving the images to the camera roll. All the other buttons on the toolbar are working fine (previous, next and play) except for the one I've created by overriding in the subclass file. I am getting the dreaded 'unrecognized selector sent to instance' error when I click the button.

My subclass TTphotoviewcontroller is inside a navigation controller which in turn is inside a navigation controller of a tabbarcontroller.

The top nav controller has a view controller with an in-app purchase button. After purchase the user goes through to the wallpaper section containing the subclass TTphotoviewcontroller inside a navigation controller (hope that makes sense).

I have checked all the linker settings. I have used some of the code that can be found here

tabbar - navigation controller - in-app purchase view controller - navigation controller - subclass photoviewcontroller - clickActionItem selector method for button

I create the button like so:

     _clickActionItem = [[UIBarButtonItem alloc] 
                          initWithBarButtonSystemItem:UIBarButtonSystemItemAction 
                          target:self action:@selector(clickActionItem)];

and fire with this:

    - (void) clickActionItem: (id)sender
 {
    NSURL *aUrl  = [NSURL URLWithString:[_centerPhoto URLForVersion:TTPhotoVersionLarge]];
                NSData   *data = [NSData dataWithContentsOfURL:aUrl];
                UIImage  *img  = [[UIImage alloc] initWithData:data];

                NSLog(@"photo:class %@", [img class]);

                UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
    }
È stato utile?

Soluzione

I think there is simple mistake by you that you are forgotten to give ':' after your @selector method.

_clickActionItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
                    UIBarButtonSystemItemAction
 target:self action:@selector(clickActionItem:)];

My suggestion will be that if you didn't create the selector method before calling it then always do copy and paste of the complete name of the method so this type of error can get reduced.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top