2011-09-29 20 views
0

如何使用索引來使用NSMutableArray?使用NSMutableArray

我想索引例如9以及高達9,0到8的所有內容都需要放在數組的末尾,以便數組看起來像這樣。

9,10,11,12,13,0,1,2,3,4,5,6,7,8

在定位方面。

這是如何在目標C中完成的?

感謝

+0

要旋轉陣列? – Anand

+0

啊,這將是「重新安排」,而不是「訴諸」。使用subarrayWithRange提取單獨的部分,然後使用addObjectsFromArray將它們重新組合到一個新數組中。 –

+0

儘管您可以使用例如sortedArrayUsingFunction將數組分類到您想要的序列中,但是如果可以根據數組值來定義序列。 –

回答

1

如果你只是想移動 OBJETS在指數 0-8到數組的結尾,那是很容易的:

NSRange r = NSMakeRange(0,9); // the range of items to push to the end 
// extract the first 9 items in the array to keep them around 
NSArray* first9 = [yourArray subarrayWithRange:r]; 
// remove them from the original NSMutableArray 
[yourArray removeObjectsInRange:r]; 
// add them back to the end 
[yourArray addObjectsFromArray:first9]; 
0

的NSMutableArray實現所有NSArray做排序功能。

相關問題