title: Use of Delegates to Communicate Between View Controllers
body: <p>After asking some questions, I learned how to send orders from one view controller to another and managed to write the code its working but nothing happens...</p>
  
  <p>In my project I have two view controllers named as <code>sayfa1</code> and <code>sayfa23</code>. When a button at <code>sayfa1</code> is clicked it will open up <code>sayfa23</code> and write on a label (random hello see the code below) but its not happening. On simulator that button only opens up the <code>sayfa23</code> and thats it nothing happening to label. If you look at the code you can understand it better.</p>
  
  <p>sayfa1.h</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @protocol sayfa1Delegate &lt;NSObject&gt;
  
  - (void)dealWithButton1;
  
  @end
  
  
  @interface sayfa1 : UIViewController
  
  @property(nonatomic,assign) id&lt;sayfa1Delegate&gt; delegate;
  
  @end
  </code></pre>
  
  <p>sayfa1.m</p>
  
  <pre><code>#import "sayfa1.h"
  
  @interface sayfa1 ()
  
  @end
  
  @implementation sayfa1
  
  @synthesize delegate;
  
  -(IBAction)button
  {
      [delegate dealWithButton1];
  }
  
  @end
  </code></pre>
  
  <p>sayfa23.h</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import "sayfa1.h"
  
  @interface sayfa23 : UIViewController &lt;sayfa1Delegate&gt; 
  {
      IBOutlet UILabel *label;
      sayfa1 *vc1 ;
  }
  
  @end
  </code></pre>
  
  <p>sayfa23.m</p>
  
  <pre><code>#import "sayfa23.h"
  #import "sayfa1.h"
  
  @interface sayfa23 ()
  
  @end
  
  @implementation sayfa23
  
  - (void)dealWithButton1
  {
      vc1.delegate = self;    
      int random_num;
      random_num = (arc4random() % 5 - 1) + 1;
      if (random_num == 1)
      { 
          label.text = @"hello1";    
      }
      else if (random_num == 2)
          label.text = @"hello2";
      else if (random_num == 3)
          label.text = @"hello3";
      else if (random_num == 4)
          label.text = @"hello4";
  }
  
  @end
  </code></pre>
  
  <p>After writing this code I connected the button to <code>sayfa23</code> so it will open the new page also I connected that button to <code>sayfa1</code> to receive button actions and I connected label (on <code>sayfa23</code>) to <code>sayfa23</code> receive label orders. But as I say nothing happens no errors and no hello what I am doing wrong? I imported <code>sayfa1.h</code> or <code>sayfa23.h</code> at the top of some of my h files cause Xcode give me an error about not defined and solved that problem but is it my mistake or something else.</p>
  
  <p>Example of I want.</p>
  
  <ul>
  <li><p>User opens the app</p></li>
  <li><p><code>sayfa1</code> shown on screen</p></li>
  <li><p>User clicks the button and <code>sayfa23</code> is shown the label text on <code>sayfa23</code> is changed by the button which is at <code>sayfa1</code> it write random hello1..2..3 etc...</p></li>
  </ul>
  
  <p>What I am doing wrong?</p>