Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is not a safe way to be passing information between controllers. If you are using this in your application, and it's working, I am actually very surprised.</p> <p>The proper way to do this is to actually pass the value you need from one controller to the other. The example below uses the Application Delegate to store the value, and then each controller reads/writes to it... <strong>it's just an example, be careful about about using the Application Delegate as a repository for what become effectively global variables</strong>. Setting up lots of variables in the Application Delegate for use in this manner will make your application difficult to maintain.</p> <p>In your App Delegate.h</p> <pre><code>@interface AppDelegate : NSObject &lt;UIApplicationDelegate&gt; { int sharedInt; } @property int sharedInt; </code></pre> <p>In your App Delegate.m</p> <pre><code>@synthesize sharedInt; // this will automatically create the getters and setters </code></pre> <p>Then in the controller where you want to set the value:</p> <pre><code>ApplicationDelegateClassNameHere * applicationDelegate = [[ UIApplication sharedApplication] delegate]; applicationDelegate.sharedInt = 3; </code></pre> <p>Then in the controller where you want to read the value:</p> <pre><code>ApplicationDelegateClassNameHere * applicationDelegate = [[ UIApplication sharedApplication] delegate]; if (applicationDelegate.sharedInt == 3) { //do your stuff here } </code></pre> <p><strong>Edited</strong>: forgot the @synthesize.<br> <strong>Edited</strong>: typed the return from the delegate singleton method, based on a suggestion from Kenneth Ballenegger, to eliminate the compiler warnings.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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