Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are several things to do. Depending on the app, you could either add a variable to the AppDelegate class, making it availible to all classes through a shared instance. The most common thing (I think) is to make a singleton. For that to work, you can make a class, say StoreVars, and a static method that returns the object, which makes the class "global". Within the method, you initialize all your variables, like you always would. Then you can always reach them from wherever.</p> <pre><code>@interface StoreVars : NSObject @property (nonatomic) NSArray * mySharedArray; + (StoreVars*) sharedInstance; @implementation StoreVars @synthesize mySharedArray; + (StoreVars*) sharedInstance { static StoreVars *myInstance = nil; if (myInstance == nil) { myInstance = [[[self class] alloc] init]; myInstance.mySharedArray = [NSArray arrayWithObject:@"Test"]; } return myInstance; } </code></pre> <p>This will make a singleton. If you remember to import "StoreVars.h" in your two viewControllers, you can access the now shared array like this;</p> <pre><code>[StoreVars sharedInstance].mySharedArray; ^ </code></pre> <p>This is a method returning a StoreVars object. Within the StoreVars class, you can implement any object and initialize it in the static method. Just always remember to initialize it, or else, all your object will be 0/nil.</p> <p>If you are not a fan of the UINavigationController and would rather use segues, it's a lot easier, but can make your app rather "messy" imo. There is a method implemented in UIViewController you should overload:</p> <pre><code>- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Make sure your segue name in storyboard is the same as this line if ([[segue identifier] isEqualToString:@"YOUR_SEGUE_NAME_HERE"]) { // Get reference to the destination view controller YourViewController *vc = [segue destinationViewController]; // Pass any objects to the view controller here, like... [vc setMyObjectHere:object]; } } </code></pre> <p>source: <a href="https://stackoverflow.com/questions/7864371/ios5-how-to-pass-prepareforsegue-an-object">How to pass prepareForSegue: an object</a></p> <p>Do some research before asking questions like this. Read some tutorials, and try out yourself, and then ask questions related to what you are really looking for. It's not everyday people want to do all the work for you, but sometimes you're lucky. Like today.</p> <p>Cheers.</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.
    3. 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