IOS 和 Objective C - 如何在 Tableview 中的 NSUserDefaults 中显示 NSDictionaries 的 NSMutableArray?
基本上我有一个 NSDictionaries 的 NSMutableArray 存储到 NSUserDefaults 中。
我已在我的应用程序中实现了表格视图,但我不确定如何显示各个值。我知道我没有提供太多信息(例如我使用的键),但是任何人都可以给我一个关于如何访问 NSDictionaries 中存储的值的基本示例吗?
下面的代码显然不起作用,但如果它只是一个字符串,则可以通过以下方式访问:
cell.textLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"parked locations"];
Basically I have an NSMutableArray of NSDictionaries stored to NSUserDefaults.
I have implemented tableview into my app but I am not sure how to display the individual values. I know that I am not providing much information (such as the keys I used) but could anyone give me a basic example on how access the values stored in NSDictionaries?
The code below doesn't work obviously, but if it were just a string it would be accessible in this way:
cell.textLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"parked locations"];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您存储了可变数组,则可以使用键
@"parkedlocations"
访问NSMutableArray
:该数组的每个元素都是一个
NSDictionary
您可以这样访问:最后在每个字典中,访问诸如
NSString
之类的值:由于
NSUserDefaults
可以存储类型为:NSData
的对象,NSString
、NSNumber
、NSDate
、NSArray
或NSDictionary
,是的,如果是的话只是一个字符串,你可以像你写的那样访问它。您可以在 集合编程主题和用户默认值编程主题
If you stored mutable arrays in, you can access the
NSMutableArray
with the key@"parked locations"
:Each element of that array is a
NSDictionary
you access like that :Finally inside each dictionary, access values like, for example
NSString
:As
NSUserDefaults
can store objects of type :NSData
,NSString
,NSNumber
,NSDate
,NSArray
, orNSDictionary
, yes, if it were just a string, you could access it like you wrote.You will find more information in Collections Programming Topics and User Defaults Programming Topics