When a user selects a row in UITableViewController, I want to segue to another viewController and set its UIImageView to a previously set image. For now, I am making it generic – always show /images/en.jpeg.
flickrTVC.m (UITableViewController):
@implementation flickrTVC
...
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"showPhoto"])
UIImage *photo = [UIImage imageWithContentsOfFile:@"images/en.jpeg"];
[segue.destinationViewController setDisplayedPhoto:photo];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"showPhoto" sender:self];
}
I have -(void)setDisplayedPhoto:(UIImage *)image; (it sets self.photo to image) in my photoViewController.h (segue.destinationViewController).
I am getting
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController setDisplayedPhoto:]: unrecognized selector sent to instance 0x1f5c4a60'
on the following line: [segue.destinationViewController setDisplayedPhoto:photo];. Even with the implementation blank, the error still shows up.
I am new to objective-c and, probably, I am just messing some things up.
Any help would be appreciated.
Thanks!
The exception occurs because the object that was there does not define the method
setDisplayedPhoto:. This could be because thesegue.destinationViewControlleris currently set to a completely different controller (e.g. for a different view than you think). It could also be that you’ve defined something similar to that method but not exactly the same; if so then the compiler has probably issued a warning about thesetDisplayedPhoto:method call.