2011-10-25 30 views
1
NSSortDescriptor* sortOrder = [NSSortDescriptor sortDescriptorWithKey: @"self" ascending: NO]; 
NSLog(@"%@",[ratio sortedArrayUsingDescriptors: [NSArray arrayWithObject: sortOrder]]); 

我排序的數組,但不能從數組中選擇最大和最小的對象。我怎樣才能做到這一點?Sorted Array選擇最大和最小的對象

NSLog屏幕如下所示; 99, 99, 99, 91, 91, 88, 88, 88, 88, 77, 77, 66, 66, 66,

我怎樣才能採取objectforkey:0在有序陣列

+0

的可能重複[我怎樣才能採取的NSArray最大對象](http://stackoverflow.com/questions/7876958/how-can-i-take-nsarray-biggest-object) –

回答

1

你試過[array objectAtIndex:0][array lastObject]?你應該通過它們的索引訪問數組的元素,而不是objectForKey:

id first = [array objectAtIndex:0]; 
id last = [array lastObject]; 
1
NSArray *sortedArray = [ratio sortedArrayUsingDescriptors: [NSArray arrayWithObject: sortOrder]]; 
NSLog(@"Biggest : %@", [sortedArray objectAtIndex:0]); 
NSLog(@"Smallest : %@", [sortedArray lastObject]); 
+0

我試圖編碼。但看起來像圖9中, 9, 9, 8, 7, 7, 6, 43, 4, 4, 31, 30, 29, 29, 28, 27, 27,我想下降對象:( – coexploit