-1

This is my code:

- (IBAction) buttonPressed:(id)sender
{
    DestinationViewController *destinationViewController = [[self.storyboard instantiateViewControllerWithIdentifier:@"Destination"] autorelease];
    destinationViewController.title = @"image property";
    destinationViewController.img = [UIImage imageNamed:@"thumbnail"];

    [self.navigationController pushViewController:destinationViewController animated:YES];

    [destinationViewController release];
}

The output is:

2012-07-20 10:43:29.976 jsonimage2[682:f803] 5 - fifth activity -http://i1184.photobucket.com/albums/z328/iElmoTutorials/CrazyEye.png
2012-07-20 10:43:31.878 jsonimage2[682:f803]  The button's image is <UIImage: 0x6aa16c0>.
2012-07-20 10:43:33.846 jsonimage2[682:f803] it works
2012-07-20 10:43:33.861 jsonimage2[682:f803] -[ViewController setImg:]:  unrecognized selector sent to instance 0x68a8b80
Cœur
  • 37,241
  • 25
  • 195
  • 267
srinu
  • 7
  • 5
  • First of all, it should be thubnail.extention for example thumbnamil.png. And where are you getting crash? – Nitish Jul 20 '12 at 05:33
  • hey have you synthesized your "img object" in destinatioviewcontroller – Leena Jul 20 '12 at 05:53
  • Ya I synthesized "img object" in DestiantionViewController. – srinu Jul 20 '12 at 08:37
  • Possible duplicate of [How can I debug 'unrecognized selector sent to instance' error](https://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-selector-sent-to-instance-error) – Cœur Jul 08 '19 at 05:51

3 Answers3

0

From the doc, instantiateViewControllerWithIdentifier: returns a __kindof UIViewController *.

Your code is attributing it to a DestinationViewController *, but actually it was returning ViewController * according to the crash log. So you probably forgot to set the class of "Destination" correctly in the Storyboard.

Cœur
  • 37,241
  • 25
  • 195
  • 267
-1

The line that sets destinationViewController.img would trigger an implicit call to setImg:.

I can't see the definition of DestinationViewController but it apparently does not contain a definition of the img property. You can either implement this by adding an apprpropriate @property for img, or by implementing the setImg: and img methods.

Kevin Grant
  • 5,363
  • 1
  • 21
  • 24
-1

you should forget @synthesize img right after @implementation DestinationViewController

Kurosawa Hiroyuki
  • 1,217
  • 2
  • 14
  • 22