“根” AppDelegate 无法识别 plist 中的密钥?

发布于 2024-11-28 21:15:51 字数 764 浏览 0 评论 0原文

我有一个简单的问题:为什么“originArray”返回(null)?我发现,如果我将所有代码放入 RootViewController 中,它就可以工作,但如果我将其放入 AppDelegate 中(因为它位于示例代码中,我不知道哪种方式更好?),它无法识别“ Root”键:

- (id)init {
    self = [super init];
    if (self){
        NSString *path = [[NSBundle mainBundle] bundlePath];
        NSString *finalPath = [path stringByAppendingPathComponent:@"origine.plist"];
        origine = [[NSDictionary dictionaryWithContentsOfFile:finalPath]retain];
    }
    return self;
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    NSLog(@"origine data : %@", origine);
    NSArray *origineArray = [origine objectForKey:@"Root"];
    NSLog(@"origineArray data : %@", origineArray);

感谢您的帮助

i have a simple question : why does "origineArray" return (null) ? i found out that if i put all the code in the RootViewController it works, but if i put it in the AppDelegate (as it is in a sample code, i don't which way is better?) , it does not recognize the "Root" key :

- (id)init {
    self = [super init];
    if (self){
        NSString *path = [[NSBundle mainBundle] bundlePath];
        NSString *finalPath = [path stringByAppendingPathComponent:@"origine.plist"];
        origine = [[NSDictionary dictionaryWithContentsOfFile:finalPath]retain];
    }
    return self;
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    NSLog(@"origine data : %@", origine);
    NSArray *origineArray = [origine objectForKey:@"Root"];
    NSLog(@"origineArray data : %@", origineArray);

Thanks for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心房敞 2024-12-05 21:15:51

如果您的应用程序委托是在 nib 文件中创建的,则不会调用 init 方法。笔尖中的项目已存档并已初始化。

如果您想要初始化从 NIB 加载的对象,请实现 - (void) awakeFromNib 方法。

If your application delegate is created in a nib file, the init method is not called. Items in nibs are archived already initialized.

If you want initialization of an object loaded from a NIB, implement the - (void) awakeFromNib method.

手心的温暖 2024-12-05 21:15:51

您正在记录“原始”字典,它会记录到控制台什么?如果“Root”键不存在,那么显然您没有打开正确的文件。如果字典为 NULL,则需要修复路径。

您确定 finalPath 包含正确的路径吗?似乎 origin.plist 位于资源文件夹中,但您正在查找器中使用应用程序包的位置。

You are logging the "origine" dictionary, what does it log to the console? If the "Root" key is not there then you are not opening the right file obviously. If the dictionary is NULL then you need to fix the path.

Are you sure that finalPath contains the right path? It seems that the origin.plist is in the resources folder but you are using the location of your app bundle in the finder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文