Saturday, August 11, 2012

To access the delegate variable

1.To access the Appdelegate varaiables


demo123AppDelegate.h


@interface demo123AppDelegate : NSObject <UIApplicationDelegate>

{
// To decleare the variables
Ex:

NSMutableArray *img_Preview;
}


demo123AppDelegate.m


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

img_Preview=[[NSMutableArray alloc]init];

// Override point for customization after application launch.
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}


demo123ViewController.h

// Declare the Delegate class

@class demo123AppDelegate;

@interface demo123ViewController : UIViewController
{
// create a instance for delegate class

demo123AppDelegate *appDelegate;

}




demo123ViewController.m

// import the delegate class here

#import "demo123AppDelegate.h"

- (void)viewDidLoad
{
appDelegate=(demo123AppDelegate *)[[UIApplication sharedApplicatio]delegate];

[super viewDidLoad];
}

// To access the variable appDelegate.img_Preview

No comments:

Post a Comment