0

In this game that I am building, I want to be able to change the image in a different view. I want to do this because there are some many different images to choose from and I want to organize them in a different view. So how can I do this?

In the first view i have 1 image view + a button to go the the view to change the image. In the second view i have some images with a transparent button over them (so i can click them), it will bring back the player when it is click. All i need now is to change the image in the first view when one of the button is clicked in the seconds view.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Kyle Greenlaw
  • 737
  • 1
  • 8
  • 20

1 Answers1

4

You can use a delegate protocol. This way you can tell the delegate that something has happened and it can then respond accordingly.

Lets say that you have a UIViewController and 2 views. One view might declare a delegate protocol like

@protocol MyViewDelegate <NSObject>

- (void)myView:(MyView *)view didPickImage:(UIImage*)image;

@end

Your view controller might implement this protocol and when the user selects the image you can call

[delegate myView:self didPickImage:image];

The viewController would then set the image in your other view.

Mohannad A. Hassan
  • 1,650
  • 1
  • 13
  • 24
Gianluca Tranchedone
  • 3,598
  • 1
  • 18
  • 33
  • Do you think you could simple it down, im new to developing. – Kyle Greenlaw Jun 23 '13 at 15:49
  • Check [this answer](http://stackoverflow.com/a/17192587/737105) I gave about protocols, and [this question about delegates](http://stackoverflow.com/questions/626898/how-do-i-create-delegates-in-objective-c). – Gianluca Tranchedone Jun 23 '13 at 18:04