Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First off, get yourself familiarized with how to use protocols and call methods between 2 different view controllers from this answer <a href="https://stackoverflow.com/questions/8623994/how-to-use-delegate-methods-to-pass-objects-between-two-view-controllers/8624090#8624090">How to use delegate methods to pass objects between two view controllers?</a>.</p> <p>Let object1(ViewController1) have the imageView and object2(ViewController2) have the buttons. All of the buttons are connected to a single method. I assume you have the images in object1. So, what you need is use some kind of way to identify the image in object1, perhaps the button's tag. Now you should have an object <code>delegate</code> in object2 which points to object1. You can then call in the button method</p> <pre><code>[self.delegate changeImageTo:button.tag]//I am just using tag in this case, but you can use other ways </code></pre> <p>In your ViewController1, you should implement the <code>changeImageTo:</code></p> <pre><code>-(void) changeImageTo:(NSUInteger)imageID { imageView.image=//get it from the image source using imageID [imageView setNeedsDisplay]; } </code></pre> <p>Create a protocol in <code>ViewContoller2</code> as <code>ViewController2Delegate</code></p> <pre><code>@protocol ViewController2Delegate -(void) changeImageTo:(NSUInteger)imageID; @end </code></pre> <p>and create delegate as an instance variable in <code>ViewController2</code> class.</p> <pre><code>id &lt;ViewController2Delegate&gt; delegate; </code></pre> <p>Don't forget to create a property for it too. </p> <pre><code>@property (nonatomic,assign) id &lt;ViewController2Delegate&gt; delegate; </code></pre> <p>and synthesize in the .m file</p> <pre><code>@synthesize delegate; </code></pre> <p>And implement <code>ViewController2Delegate</code> protocol in <code>ViewController1</code> class.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload