iPhone-Xcode找不到plist,或者plist读取不正确

iPhone-Xcode找不到plist,或者plist读取不正确,iphone,plist,Iphone,Plist,我在读取自定义plist时遇到问题。我在这里和其他地方找到了苹果的文档和许多帖子,但我无法理解我做错了什么 我的plist是一个有两个字符串(URL)的字典 这是我的代码,就像苹果和其他网站一样: - (void)accessPlistForURLDictionary { NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); NSStri

我在读取自定义plist时遇到问题。我在这里和其他地方找到了苹果的文档和许多帖子,但我无法理解我做错了什么

我的plist是一个有两个字符串(URL)的字典

这是我的代码,就像苹果和其他网站一样:

- (void)accessPlistForURLDictionary
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsPath = [paths objectAtIndex:0];
    NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"server_urls.plist"];

    if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath])
    {
        // if not in documents, get property list from main bundle
        plistPath = [[NSBundle mainBundle] pathForResource:@"server_urls" ofType:@"plist"];
        NSLog(@"bundle");
    }

    NSData *xml = [[NSFileManager defaultManager] contentsAtPath:plistPath];
    NSString *error = nil;
    NSPropertyListFormat format;
    // convert static property liost into dictionary object
    NSDictionary *plistDictionary = (NSDictionary *)[NSPropertyListSerialization propertyListFromData:xml mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&error];
    if (!plistDictionary)
    {
        NSLog(@"Error reading plist: %@, format: %d", error, format);
    }

    serverURL = [[plistDictionary objectForKey:@"Root"] objectForKey:@"get_firstview"];
    NSLog(@"serverURL in accessPlist is: %@", serverURL);
}
这是日志。。。。我不明白为什么serverURL(一个合成的字符串变量)是“null”

2013-01-07 12:47:06.742 ME[2305:c07] bundle
2013-01-07 12:47:06.744 ME[2305:c07] serverURL in accessPlist is: (null)
2013-01-07 12:47:06.744 ME[2305:c07] serverURL is: (null)
最后一次检查是在viewDidLoad中使用serverURL之前完成的


我在构建设置中添加了plist(我想)。我的代码一定有问题,但我找不到什么。

有更简单的方法将
plist
加载到
NSDictionary

NSMutableDictionary *plistDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile: plistPath];

试试看。

谢谢!我想我以前在所有的尝试中都试过了,但出于某种原因,我成功了。太容易了,我觉得不好意思。