NSMutableArray *full_text_list = [[NSMutableArray alloc]init];
[full_text_list addObject:@"for"];
[full_text_list addObject:@"for your information"];
[full_text_list addObject:@"you"];
[full_text_list addObject:@"at"];
NSMutableArray *short_text_list = [[NSMutableArray alloc]init];
[short_text_list addObject:@"4"];
[short_text_list addObject:@"fyi"];
[short_text_list addObject:@"u"];
[short_text_list addObject:@"@"];
我不想排序第二個數組。我想獲得基於索引的適當元素。 我想基於長度排序只有full_text_list陣列,所以我嘗試了以下分類和匹配
NSSortDescriptor * descriptors = [[[NSSortDescriptor alloc] initWithKey:@"length"
ascending:NO] autorelease];
NSArray * sortedArray = [full_text_list sortedArrayUsingDescriptors:
[NSArray arrayWithObject:descriptors]];
和上面的代碼工作fine.But我不知道如何short_text_list陣列新數組排序匹配
So when doing like [full_text_list objectatindex:0] and [short_text_list objectatindex:0] will not match
result would be "for your information" and "for" but the result should be "for your information" and "fyi"
請讓我知道
這裏我們需要怎樣排序? – user198725878 2012-03-21 06:35:06
使用以前使用的完全相同的代碼。實際上,您並未在此處對字典進行排序,只是將原始的full_text_list和使用您創建的sortedArray進行排序。然後,查找字典中的full_text_list值(即sortedArray中的值)以查找與之匹配的short_text_list值。 – lnafziger 2012-03-21 06:38:19
我剛更新了這個例子。 – lnafziger 2012-03-21 06:40:22