dev*_*ost -1 sorting objective-c ios
首先,这是我的代码:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL
URLWithString:url]];
NSData *response = [NSURLConnection sendSynchronousRequest:request
returningResponse:nil error:nil];
NSDictionary *publicTimeline = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonParsingError];
for (NSObject* key in publicTimeline) {
id value = [publicTimeline objectForKey:key];
NSLog(@"%@", key);
}
Run Code Online (Sandbox Code Playgroud)
我在网络服务上收集了一些新闻,并在tableView中显示它.
我的问题是这些新闻没有按顺序显示.
在我的网络服务中,新闻是有序的,例如我有:
{"0":{"title":"News1"}}
{"1":{"title":"News2"}}
{"2":{"title":"News3"}}
Run Code Online (Sandbox Code Playgroud)
等等..
但是在循环中,我"松散"了这个顺序:/我希望按此顺序获得我的新闻,首先是"1"之后索引为"0"的新闻等...
(NSDictionary似乎放弃了这个顺序,例如,在我的代码之后,我在我的tableview中,新闻:"2","0","1",而不是我的新闻"0","1"," 2".)
(我尝试了一些答案,但似乎没有一个在我的情况下工作:()
SOmeone来帮助我吗?谢谢,
这是我上次用来排序字典键的内容.希望你能更容易实现它:)
NSMutableArray *sortedArray = [NSMutableArray arrayWithArray:publicTimeline.allKeys];
[sortedArray sortUsingSelector:@selector(localizedStandardCompare:)];
Run Code Online (Sandbox Code Playgroud)
你应该在sortedArray中有你的排序键