Ø (2)Global
Vriable Concept
ip6AppDelegate.h
@class ip6ViewController;
@interface ip6AppDelegate : UIResponder
<UIApplicationDelegate>
{
BOOL myAppDelVar;
int myAppDelVar2;
}
@property (nonatomic, readwrite) BOOL myAppDelVar;
@property (nonatomic, readwrite) int myAppDelVar2;
ip6AppDelegate.m
#import "ip6AppDelegate.h"
#import "ip6ViewController.h"
@synthesize myAppDelVar, myAppDelVar2;
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
myAppDelVar = 0;
myAppDelVar2 = 1;
self.window =
[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point
for customization after application launch.
self.viewController = [[ip6ViewController alloc]
initWithNibName:@"ip6ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window
makeKeyAndVisible];
return YES;
}
ip6ViewController.h
#import <UIKit/UIKit.h>
extern int myGlobal;
@class ip6AppDelegate;
@interface ip6ViewController : UIViewController
{
ip6AppDelegate
*appDelObj;
}
- (IBAction)clickBtnPressed:(id)sender;
@end
ip6ViewController.m
#import "ip6ViewController.h"
#import "ip6AppDelegate.h"
#import "ip6View2.h"
@implementation ip6ViewController
int myGlobal;
- (IBAction)clickBtnPressed:(id)sender
{
ip6View2 *ip6View2VC
= [[ip6View2 alloc] initWithNibName:@"ip6View2" bundle:nil];
[self
presentViewController:ip6View2VC animated:YES completion:nil];
}
- (void)viewDidLoad
{
[super
viewDidLoad];
appDelObj =
(ip6AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelObj.myAppDelVar = 1;
appDelObj.myAppDelVar2 = 100;
NSLog(@"AppDelVars: %d, %d", appDelObj.myAppDelVar,
appDelObj.myAppDelVar2);
myGlobal = 100;
}
- (void)viewWillAppear:(BOOL)animated
{
NSLog(@"%d", myGlobal);
}
ip6View2.h
- (IBAction)back:(id)sender;
ip6View2.m
#import "ip6View2.h"
#import "ip6ViewController.h"
- (IBAction)back:(id)sender
{
[self
dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewDidLoad
{
[super
viewDidLoad];
myGlobal = 101;
}
No comments:
Post a Comment