自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

了解iPhone開發(fā)中關(guān)于NSMutableArray排序?qū)嵗?/h1>

移動開發(fā) iOS
了解iPhone開發(fā)中關(guān)于NSMutableArray排序?qū)嵗潜疚囊榻B的內(nèi)容,主要是來了解NSMutableArray的排序操作,具體實(shí)現(xiàn)來看本文詳解。

了解iPhone開發(fā)中關(guān)于NSMutableArray排序實(shí)例是本文要介紹的內(nèi)容,主要是來了解NSMutableArray排序操作,內(nèi)容不多,主要是基于代碼實(shí)現(xiàn)內(nèi)容,來看詳細(xì)代碼。

  1. - (NSArray *)sortedArrayUsingSelector:(SEL)comparator  
  2.  
  3. Parameters  
  4. comparator  
  5.  
  6. A selector that identifies the method to use to compare two elements at a time. The method should returnNSOrderedAscending 
  7. if the receiver is smaller than the argument, NSOrderedDescending if the receiver is larger than the argument,
  8.  and NSOrderedSame if they are equal  
  9. NSArray *sortedArray =  
  10.  
  11. [anArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];  
  12. @property (nonatomic, readwrite, retain) NSMutableArray *parameters;  
  13. [self.parameters sortUsingSelector:@selector(compare:)];  
  14. #pragma mark -  
  15.  
  16. - (NSComparisonResult)compare:(id)inObject {  
  17.      NSComparisonResult result = [self.name compare:[(MPURLRequestParameter *)inObject name]];  
  18.      if (result == NSOrderedSame) {  
  19.  result = [self.value compare:[(MPURLRequestParameter *)inObject value]];  
  20.      }  
  21.       return result;  
  22. }  
  23.  
  24. sortedArrayUsingFunction:適合基本類型(支持compare方法)  
  25.  
  26. #pragma mark SORT METHOTDS  
  27. NSInteger sortObjectsByLatestTime(id obj1, id obj2, void *context)  
  28. {  
  29.  NSDate* d1 = [(MessageGroup*)obj1 latestTime];  
  30.  NSDate* d2 = [(MessageGroup*)obj2 latestTime];   
  31.  //sort by desc  
  32.  return [d2 compare:d1];  
  33. }  
  34. NSInteger dateSort(id obj1, id obj2, void *context)  
  35.  
  36. {  
  37.  NSDate* d1 = ((Inbox*)obj1).datetime;  
  38.  NSDate* d2 = ((Inbox*)obj2).datetime;  
  39.  return [d1 compare:d2];  
  40. }  
  41.  
  42. -(NSArray*)sortedMessages  
  43. {  
  44.  return [[groupMessages allValues] sortedArrayUsingFunction:sortObjectsByLatestTime context:NULL];  
  45. }  
  46.  
  47. sortUsingDescriptors:適合元素是dict類型,initWithKey既是dict key.  
  48.  
  49. NSMutableArray *regions = [NSMutableArray array];  
  50. NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];  
  51. NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];  
  52. [regions sortUsingDescriptors:sortDescriptors];  
  53. [sortDescriptor release]; 

小結(jié):了解iPhone開發(fā)中關(guān)于NSMutableArray排序實(shí)例的內(nèi)容介紹完了,希望通過本文的學(xué)習(xí)能對你有所幫助!

責(zé)任編輯:zhaolei 來源: 網(wǎng)易博客
相關(guān)推薦

2011-08-04 17:19:49

iPhone開發(fā) Xcode 文檔

2011-08-09 17:12:30

iPhoneCFRunLoop

2011-07-29 13:27:48

iPhone 開發(fā) Nib

2011-08-22 14:21:24

iPhone開發(fā)UIView Anim

2011-07-25 18:02:51

iPhone LibFetion 移植

2011-08-15 13:44:07

iPhone開發(fā)UITableView

2011-08-08 16:56:44

iPhone 字符處理 視圖

2011-08-08 14:07:49

iPhone開發(fā) 字體

2011-08-15 09:58:25

iPhoneXib文件UITableView

2011-08-16 18:56:11

iPhone開發(fā)Three20

2011-08-02 13:35:41

iOS開發(fā) Get Post

2011-08-08 10:23:41

iPhone 流播放 文件

2011-07-06 17:40:43

iPhone SDK

2011-07-19 15:33:57

iPhone

2011-08-18 10:39:46

iPhone開發(fā)界面

2011-08-19 10:35:19

iPhone應(yīng)用Three20

2011-08-08 15:56:18

iPhone 震動 NSUserDefa

2011-07-27 11:19:33

iPhone UITableVie

2011-07-28 10:11:54

iPhone開發(fā) 備忘

2011-07-21 17:00:59

iPhone UIWebView Status Cod
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號