如何对二维多维 NSMutablearray 进行排序
首先我想对我糟糕的英语表示抱歉。我希望你能理解。
我搜索了三天多的时间来寻找我的问题,但没有找到解决方案:( 我有一个包含 NSMutablearrays 的 NSMutablearray 。
我从网上获取数据。网络输出如下所示:
( ("Restaurant2" , "10" , "酒店" , "Solitudestr" , "德国" , "48.81155" , "9.10903"),("俱乐部 2" , "14" , "俱乐部" , "Weilimdorfer213" , "德国" , "48.814" , "9.1311666666667"),("泰国肉" , "22" , “Gastro”、“Weilimdorfer193”、“70469 斯图加特”、“48.813833333333” ,“9.1328333333333”))
所以我在一个 NSMutablearray 中有 3 个 NSMutablearray。我正在使用自定义单元视图在我的 Tableview 中显示数组。
我的问题是如何使用第一个值对三个内部数组进行排序。 (第一个值的值:Restaurant2、Club 2、Thai Meat)
因此第一个数组应该是:
("俱乐部 2" , "14" , "俱乐部" , "Weilimdorfer213" , "德国" , "48.814" , “9.1311666666667”)
第二个:
("Restaurant2"、"10"、"酒店"、"Solitudestr"、"德国"、 “48.81155”,“9.10903”)
第三:
(“泰国肉”、“22”、“美食”、“Weilimdorfer193”、“70469 斯图加特", "48.813833333333", "9.1328333333333")
我应该使用哪个排序函数以及如何使用?
在第二步中,我想获取给定坐标的距离并对到当前位置的距离进行排序。
我已经得到了距离。但是怎么排序呢
非常感谢!
First i want to say sorry about my bad english. I hope you will unterstand.
i searched over three days for my problem and I found no solution :(
i have a NSMutablearray containing NSMutablearrays.
I get the data from the web. The weboutput looks like:
( ("Restaurant2" , "10" , "Hotel" , "Solitudestr" , "Germany" ,
"48.81155" , "9.10903"),("Club 2" , "14" , "Club" , "Weilimdorfer213"
, "Germany" , "48.814" , "9.1311666666667"),("Thai Meat" , "22" ,
"Gastro" , "Weilimdorfer193" , " 70469 Stuttgart" , "48.813833333333"
, "9.1328333333333") )
So I have here 3 NSMutablearray's inside one NSMutablearray. I am showing the Array at my Tableview with a custom cellview.
My question is how can I sort the three inner arrays with first Value.
(Values of first Value: Restaurant2,Club 2,Thai Meat)
So the first array should be:
("Club 2" , "14" , "Club" , "Weilimdorfer213" , "Germany" , "48.814" ,
"9.1311666666667")
second:
("Restaurant2" , "10" , "Hotel" , "Solitudestr" , "Germany" ,
"48.81155" , "9.10903")
third:
("Thai Meat" , "22" , "Gastro" , "Weilimdorfer193" , " 70469
Stuttgart" , "48.813833333333" , "9.1328333333333")
Which sortfunction should I use and how?
In the second step I want to get the distance of the given coordinates and sort the distance to the current position.
I got the distance, already. But how to sort this?
Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您要创建一个自定义对象来存储信息,而不是使用数组,这会容易得多。
看一下 Dave DeLong 在 这篇文章。
填充
scores
数组后,您现在可以执行以下操作:此后,您的
scores
数组将按分数升序排序。看看 集合编程主题 和 NSSortDescriptor。
This would be much easier if you were to create a custom object to store the information, instead of using an array.
Take a look at this example written by Dave DeLong in this post.
Once you've populated your
scores
array, you can now do:After this, your
scores
array will be sorted by the score ascending.Take a look at Collections Programming Topics and NSSortDescriptor.