Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 05-03-2010, 11:57 PM   #12 (permalink)
irene_19891023
Registered Member
 
Join Date: Apr 2010
Posts: 7
irene_19891023 is on a distinguished road
Default still about variable shared between UIViews

Quote:
Originally Posted by WaRcLaWz View Post
Sure.

I created a blank foundation class called "Globals" that stores the variables.

Globals.h looks like this...
Code:
#import <Foundation/Foundation.h>

extern NSArray *gMapArray;
extern NSMutableArray *gPathHexArray;
extern NSMutableArray *gTerrainImageViewArray;


@interface Globals : NSObject {

}

@end
Globals.m looks like this...
Code:
#import "Globals.h"

@implementation Globals

NSArray *gMapArray;
NSMutableArray *gPathHexArray;
NSMutableArray *gTerrainImageViewArray;


@end
The external variables need to be initialized before they can be used, so I did this in the "AppDelegate.m" class...

Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {    
    
    // Override point for customization after app launch
    [window addSubview:mainMenuViewController.view];
    [window makeKeyAndVisible];

	//Initialize array that holds the terrain graphics
	gMapArray = [[NSArray alloc] init];
	//Initialize array that holds the movement hexes
	gPathHexArray = [[NSMutableArray alloc] init];
	//Initialize array that holds the terrain UIImageView objects
	gTerrainImageViewArray = [[NSMutableArray alloc] init];
}
You must make sure that you import the "Globals.h" into any class that uses the external variables, including the AppDelegate that I mentioned above. For example, in the "AppDelegate.m" you would make sure to have
Code:
#import "Globals.h"

I hope this helps!

Hello~I have known your method, but I still have a question that do i need to write "Global *global=[[Global alloc] init];" before i use those global variables? Thank you~!
irene_19891023 is offline   Reply With Quote
 

» Advertisements
» Online Users: 384
21 members and 363 guests
Absentia, alexP, blackcat_tq, Bobarino, Duncan C, eski, Farfalo, flamingliquid, Garros1990, hacker073, ilmman, jbro, mongmo, MysticLine, n00b, Newbie123, NSString, pinky, Sami Gh, SillyHoney, SuperDietGenius
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,560
Threads: 94,079
Posts: 402,743
Top Poster: BrianSlick (7,990)
Welcome to our newest member, mongmo
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:46 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.