您可以使用 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;
}