将 NSUserdefaults 读入 NSArray
我正在尝试将 Root.plist 键的值读取到 NSArray 中,以便我可以为我的应用程序设置填充表格视图。
我使用以下代码来检索键“country”的值:
NSArray *arrayCountry = [[NSUserDefaults standardUserDefaults] arrayForKey:@"country"];
NSLog(@"Number of items in array >>>>>> %d", arrayCountry.count);
NSLog 返回:
数组中的项目数>>>>> 0
我在不同的键上尝试了相同的操作,但仍然得到相同的结果。
谁能解释一下这个问题。我在这里错过了什么吗?
I am trying to read the values of Root.plist key into NSArray so I can populate a table view for my App settings.
I am using the following code to retrieve the values of the key "country":
NSArray *arrayCountry = [[NSUserDefaults standardUserDefaults] arrayForKey:@"country"];
NSLog(@"Number of items in array >>>>>> %d", arrayCountry.count);
NSLog returns:
Number of items in array >>>>>> 0
I tried the same on different keys but still get the same result.
Can anyone shed some light on this issue. Did I miss anything here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您的
arrayCountry
不是nil
。如果是,arrayCountry.count
将返回零,即使它是 nil。试试这个:
Make sure your
arrayCountry
isn'tnil
. If it is,arrayCountry.count
will return zero even if it is nil.Try this: