Terrel Gibson Terrel Gibson - 1 year ago 106
Objective-C Question

Unrecognized Selector Sent to Instance UIViewController

I keep getting the error:

NSInvalidArgumentException', reason: '-[UIViewController setPhotoCellName:]: unrecognized selector sent to instance

when I enter my prepare for segue call. Currently I have


with a UI image on it.

The problem occurs when I try to segue from the second TableView controller to the ViewController. I have the segue setup from the Prototype Cell to the actual ViewController. It enters the segue and crashes. I am trying to pass an
property over to the
to be able to use a URL in it and display the
. PhotoInPlace contains the array that Im trying to pass. Here is the code.

myTableViewControllerPhotoLocation.m Code

#import "myTableViewControllerPhotoLocation.h"
#import "FlickrImageViewController.h"

@interface myTableViewControllerPhotoLocation ()

@implementation myTableViewControllerPhotoLocation
@synthesize photoInPlace = _photoInPlace; //Contains NSArray to pass

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"Photo Display"]){
NSIndexPath* indexPath = [self.tableView indexPathForCell:sender];
NSLog(@" Dicitonary = %@", [self.photoInPlace objectAtIndex:indexPath.row]); //Returns the picked cell
NSLog(@"%@", [self.photoInPlace class]); //returns NSArray
NSLog(@"%@", [self photoInPlace]); //Returns the array

[segue.destinationViewController setPhotoCellName:[self.photoInPlace objectAtIndex:indexPath.row]];
//Crashes HERE!

FlickrImageViewController.h Code

@property (nonatomic, strong) NSArray* photoCellName;

FlickrImageViewController.m Code

#import "FlickrImageViewController.h"

@interface FlickrImageViewController ()

@implementation FlickrImageViewController
@synthesize photoCellName = _photoCellName; //property declared in header

-(void) setPhotoCellName:(NSArray *)photoCellName{
_photoCellName = [[NSArray alloc] initWithArray:photoCellName];
else {
_photoCellName = photoCellName;

Answer Source

You believe that your destination is an object from the FlickrImageViewController but the app doesn't. Look at the class you have assigned that controller in your storyboard; according to the error, it's a bare UIViewController.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download