我有这个 appdelegate.h
#import <UIKit/UIKit.h>
@interface appDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
NSString *name;
}
@property (nonatomic, retain) NSString *name;
@end
和 .m 文件
@synthesize name;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
name=@"john";
return YES;
}
现在...我想从另一个控制器获取这个名称,如果我尝试在我的 viewDidLoad 方法中调用它,它可以工作..
- (void)viewDidLoad
{
appDelegate *test= (appDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(@"%@", test.name);
}
但如果我尝试在我的 initWithNibName 中做同样的事情,它就没有用......
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
appDelegate *test= (appDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(@"%@", test.name);
}
任何人都可以帮助我吗?这个问题快把我逼疯了...