确定对象来自哪个字典
我有一个存储问题信息的 PLIST 文件。顶部是一个数组,该数组内有字典。每个字典中都有一个名为“Date”的字符串,其中包含不同的日期。然后,我在表视图中显示日期值。
我能够确定点击的 UITableview 单元格的文本(以及日期字符串),但是如何访问同一字典中的其他值?如果我知道日期字符串是2012年2月16日,如何获取“下载地址”?这是我的 PLIST 的图片:
I have a PLIST file that stores issue information. At the top is an array, and within that array there are dictionaries. Within each dictionary is a string called "Date" with different dates. I then display the date values in a table view.
I am able to determine the text of the UITableview cell tapped (and therefore the date string), but how do I then access the other values within the same dictionary? If the I know that the date string is February 16, 2012, how do I get the "Download URL"? Here is a picture of my PLIST:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该从被点击的单元格中获取indexPath。 indexPath.row 应该为您提供一个索引号,您可以使用该索引号从字典数组中获取正确的字典。如果您尚未保留此数组,并且其大小可以管理,请考虑这样做。
就我个人而言,我永远不会依赖日期的唯一性或以任何特定方式格式化。
You should be getting the indexPath from the cell that is tapped. The indexPath.row should give you an index number that you can use to get the correct dictionary from your array of dictionaries. If you are not already keeping this array, consider doing so if it's a manageable size.
Personally, I would never rely on the date being unique or formatted in any particular way.
在使用该数据初始化 TableViewController 之前,您可以按问题日期对数组(问题列表)进行排序,然后使用被点击的单元格的 NSIndexPath。
要使用字典对数组进行排序,请使用以下代码片段:
之后,您可以像这样使用 indexPath:
You can sort your array (Issue List) by the issues date before you init your TableViewController with that data and than use the NSIndexPath of the cell that was tapped.
To sort the array with the dictionaries use this snippet:
After that you can use the indexPath like that: