Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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;
    }
}
like image 894
Terrel Gibson Avatar asked Aug 03 '12 21:08

Terrel Gibson


2 Answers

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.

like image 114
Phillip Mills Avatar answered Oct 14 '22 07:10

Phillip Mills


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

like image 38
Chuck Avatar answered Oct 14 '22 06:10

Chuck