appDelegateメソッドを使用して、他のクラスから変数にアクセスできます。
例、
class2:.mファイル
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
Controller = appDelegate.viewControllerClass1;
}
return self;
}
AppDelegateクラスでは、.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewControllerClass1 = [[[Class1 alloc] init] autorelease];
NavigationController=[[UINavigationController alloc]initWithRootViewController:self.viewControllerClass1];
[self.window makeKeyAndVisible];
return YES;
}