Hi all, Ive read everything about global variables, and understand the problems but i only need one variable to be accessable by more than one view, so a global variable seems the easiest way, however i having some trouble
globals.h
globals.m
app deleagate
i then try to set it in one view using
and then try to access it in a further view
this however gives a bad access error and the applications crashes - i have included my globals file in all the relevant files, and it seems to set ok, and can be viewed in the view it is set in but will not work elses where
any help is greatly appreciated
Alan
globals.h
Code:
#import <Foundation/Foundation.h>
extern NSNumber *gcurrentGameID;
@interface globals : NSObject {
}
@end
globals.m
Code:
#import "globals.h"
@implementation globals
NSNumber *gcurrentGameID;
@end
app deleagate
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch.
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
NSNumber *gcurrentGameID = [NSNumber numberWithInt:0];
return YES;
}
i then try to set it in one view using
Code:
gcurrentGameID = [NSNumber numberWithInt:(currentRow)];
and then try to access it in a further view
Code:
NSLog("The int value was %d",[gcurrentGameID intValue]);
this however gives a bad access error and the applications crashes - i have included my globals file in all the relevant files, and it seems to set ok, and can be viewed in the view it is set in but will not work elses where
any help is greatly appreciated
Alan