2

I'm totally new to Objective-C, that's why maybe my problem could appear a little silly.

Ok, I have some ViewController in my project (with the respective classes connected) and a NavigationController that handles all the movements between them.

In my main view I've put a UIButton that pushes the app to my second view, and a UIImageView with a picture loaded.

What I'd like to do now, is to load the picture (gotten from the first view's imageView) in another UIImageView that I placed into the second view...can someone help me?

Googoling I've found this code...but it's not working...I think it's because it refers to the blank default class, and I need the active one:

- (void)viewDidLoad
{
    [super viewDidLoad];
    ViewController *viv = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.editingImageView.image = viv.myPic.image;
}

(the code I've pasted you here is on my second view)

Mind Pixel
  • 816
  • 7
  • 16
Sara Canducci
  • 6,231
  • 5
  • 19
  • 24

1 Answers1

0

You can do it by setting a UIImageView property on the second view controller, and in

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

you set the destination view controller's property as the ui image.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([segue.identifier  isEqual: @"correctIdentifierAsChosenInStoryBoard"])
    {
        ((SecondViewController *)(segue.destinationViewController)).UIImageViewPropery = UIImageViewToPass;
    }
}

EDIT: the problem was, she was setting the property of an IBOutlet that is not initialised yet. solution was to use a property to hold the image, and set it to the UIImageView in viewWillAppear.

Yoav Schwartz
  • 2,017
  • 2
  • 23
  • 43
  • I tried this one and I definitely think that's the right solution...but it's not working anyway. No errors...but no results...is there maybe something that I could have forgotten? – Sara Canducci Apr 30 '14 at 09:32
  • I need to see the new code you're using – Yoav Schwartz Apr 30 '14 at 09:35
  • Oh well, it's basically a blank project with your code. I've tried to do something more direct, like writing in a label: -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ EditingView *transferViewController = segue.destinationViewController; if([segue.identifier isEqualToString:@"seguitore"]) { transferViewController.editingLabel.text = @"Ciao"; } } // seguitore is the name of my segue – Sara Canducci Apr 30 '14 at 09:37
  • Put some breakpoints, to make sure it goes into the method, and that it goes into the IF statement – Yoav Schwartz Apr 30 '14 at 09:41
  • I did that using some NSLog and it's passing correctly – Sara Canducci Apr 30 '14 at 10:11
  • And does the label have the right text in the next view controller? – Yoav Schwartz Apr 30 '14 at 10:12
  • The label doesn't change its default value – Sara Canducci Apr 30 '14 at 10:16
  • Hmm, I'm starting to run out of ideas, the code runs without errors, and its correct as far as I can see. try logging the class name of the segue.destinationviewcontroller and see if its what you expected(as in the name of the target class) – Yoav Schwartz Apr 30 '14 at 10:21
  • I did that as well and it's ok! Click here, there's my project so you can check yourself --> http://www.seedo.it/Test1.zip – Sara Canducci Apr 30 '14 at 10:24
  • Ok, I have managed to make it work, by adding a uistring property, and setting the string as the label text in the view itself, in viewWillAppear. so with the image, I would suggest making a UIImage property instead of and then setting that image as the image of the UIImageView. I think it has something to do with the label "not existing" yet when you are trying to set it's test value. – Yoav Schwartz Apr 30 '14 at 10:36
  • Oh finally I can see the light at the end of the tunnel! Thank you so much now it's working! Thanks! – Sara Canducci Apr 30 '14 at 10:49
  • No problem :) I can remember what's its like trying to copy paste code and hope it works. people here can be pretty quick on the trigger by just sending you to the documentation. good luck with your project. – Yoav Schwartz Apr 30 '14 at 10:57
  • Thanks again! Good luck with your stuff too! :) – Sara Canducci May 01 '14 at 19:18