Unrecognized Selector Sent to Instance UIViewController

11,790

Solution 1

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.

Solution 2

It sounds like you've accidentally got a plain vanilla UIViewController rather than a FlickrImageViewController. Maybe you forgot to assign the controller's class?

Share:
11,790
Terrel Gibson
Author by

Terrel Gibson

Updated on June 14, 2022

Comments

  • Terrel Gibson
    Terrel Gibson almost 2 years

    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

    TabBarController->NavigationController->TableViewController->TableViewController->ViewController

    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 NSArray property over to the viewController to be able to use a URL in it and display the UIImage. PhotoInPlace contains the array that Im trying to pass. Here is the code.

    myTableViewControllerPhotoLocation.m Code

    #import "myTableViewControllerPhotoLocation.h"
    #import "FlickrImageViewController.h"
    
    @interface myTableViewControllerPhotoLocation ()
    @end
    
    @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 ()
    @end
    
    @implementation FlickrImageViewController
    @synthesize photoCellName = _photoCellName; //property declared in header
    
    
    -(void) setPhotoCellName:(NSArray *)photoCellName{
        if(!_photoCellName)
            _photoCellName = [[NSArray alloc] initWithArray:photoCellName];
        else {
            _photoCellName = photoCellName;
        }
    }