Issue with passing a variable through prepareForSegue method

Rmyers

I am getting an error that I can't seem to solve:

    *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
 reason: '-[UICollectionViewController setSearchString:]: unrecognized 
selector sent to instance 0x7fcd4b655930'

The error comes when I call a prepareForSegue method:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

    NSString *searchStringToPass = [[NSString alloc]initWithFormat:_inputField.text];
    UINavigationController *navController = [segue destinationViewController];
    ResultsCollectionViewController *rvc = (ResultsCollectionViewController *)([navController viewControllers][0]);
    NSLog(@"Search String to Pass is: %@", searchStringToPass);
    //[rvc setSearchString:searchStringToPass];
    rvc.searchString = searchStringToPass;
        //userViewController.user = [self.users objectInListAtIndex:[self.tableView indexPathForSelectedRow].row];

}

The ViewController that I am trying to get to is imbedded in a navigation controller. The code for it is:

#import "ResultsCollectionViewController.h"

@interface ResultsCollectionViewController ()
//@property(nonatomic, weak) IBOutlet UICollectionView *collectionView;
@property(strong, nonatomic) NSArray *flickrPhotos;


@end

@implementation ResultsCollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSLog(@"search string is %@",_searchString);
}

-(void)getFlickrPhotosWithSearchString:(NSString*)searchString{


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

And the .h file is:

#import "BaseViewController.h"

@interface ResultsCollectionViewController : BaseViewController <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (strong, nonatomic) NSString *searchString;



@end

Anybody have any idea what the issue is? Many thanks in advance.

Rob

You report the following error message:

-[UICollectionViewController setSearchString:]: unrecognized selector sent to instance 0x7fcd4b655930

Note that the "unrecognized selector" in the error message is the setter accessor method for your searchString property, but the class referenced is the standard UICollectionVieController, not your custom class.

That suggests that you neglected to specify the base class for the destination scene in Interface Builder. The storyboard has therefore instantiated a standard UICollectionViewController rather than your custom class, and thus your searchString accessor methods are not found.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related