• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            逛奔的蝸牛

            我不聰明,但我會很努力

               ::  :: 新隨筆 ::  ::  :: 管理 ::
             

            Cocoa and Objective-C: Up and Running (by me) is now available from O'Reilly.

            Inline Arrays of NSSortDescriptors

            NSSortDescriptor is Cocoa's standard class for sorting an NSTableView (or NSArray) by multiple criteria. Sort descriptors are created automatically when the user clicks on a column, but there are a number of situations where you need to create them in code. The API is really simple but the process of getting these things into the table is fairly verbose. Here's a clean and simple way to automate the process, using a category with varargs as input:


            @interface NSSortDescriptor (CDCExtensions)

            + (NSArray *) ascendingDescriptorsForKeys: (NSString *)firstKey,...;

            @end

            You can use it like this:

            NSArray *descriptors = [NSSortDescriptor
                         ascendingDescriptorsForKeys: @"subject", @"date", nil];
                    
            [tableView setSortDescriptors: descriptors];

            Or this:

            NSArray *descriptors = [NSSortDescriptor
                         ascendingDescriptorsForKeys: @"subject", @"date", nil];
                    
            NSArray *sorted = [someArray sortedArrayUsingDescriptors: descriptors];


            Grab zip file with the the .h and .m files. Here's the implementation (formatting adjusted for site):

            @implementation  NSSortDescriptor (CDCAdditions)

            + (NSArray *) ascendingDescriptorsForKeys: (NSString *)firstKey,...
            {    
              id returnArray   = [[NSMutableArray arrayWithCapacity: 5] retain];
              va_list           keyList;
                
              NSString          * oneKey;
              NSSortDescriptor  * oneDescriptor;
              
              if (firstKey)
              {
                oneDescriptor = [[NSSortDescriptor alloc] initWithKey: firstKey
                                                            ascending: YES];
                [returnArray addObject: oneDescriptor];
                [oneDescriptor release];
                
                va_start (keyList, firstKey);
                
                while (oneKey = va_arg(keyList, NSString *))
                {
                  oneDescriptor = [[NSSortDescriptor alloc] initWithKey: oneKey
                                                              ascending: YES];
                  [returnArray addObject: oneDescriptor];
                  [oneDescriptor release];
                }
                
                va_end (keyList);
              }
              
              return [returnArray autorelease];
              
            }

            @end
            Design Element
            Inline Arrays of NSSortDescriptors
            Posted Mar 15, 2005 — 3 comments below




             

            Hayssam — Mar 15, 05 114

            Hi!

            I think there might be a typo in your 
            >   NSSortDescriptor  * descriptor;
            as "descriptor" is never used while "OneDescriptor" is used but not declared.

            Thanks for sharing this snippet !

            Scott Stevenson — Mar 16, 05 115 Scotty the Leopard

            Fixed, thanks. I had tweaked a few things to fit the code on the page, and this was an artifact of that. The code in the zip file was fine, though.

            Scott Stevenson — Mar 16, 05 116 Scotty the Leopard

            Update: I added some discussion about sorting NSArrays.




             

            Comments Temporarily Disabled

            I had to temporarily disable comments due to spam. I'll re-enable them soon.




            Technorati Profile
            Copyright © Scott Stevenson 2004-2008

            From: http://theocacao.com/document.page/87

            @import url(http://www.shnenglu.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
            posted on 2011-12-02 00:01 逛奔的蝸牛 閱讀(291) 評論(0)  編輯 收藏 引用 所屬分類: Cocoa
            久久久久亚洲AV无码专区体验| 99久久国产综合精品麻豆| 2021国产精品久久精品| 久久久久人妻一区精品色| 久久精品国产精品青草app| 午夜视频久久久久一区 | 久久精品视频一| 丁香狠狠色婷婷久久综合| 亚洲国产成人乱码精品女人久久久不卡 | 亚洲一区精品伊人久久伊人| 精品久久无码中文字幕| 久久人搡人人玩人妻精品首页| 狠狠色综合网站久久久久久久高清| 欧美一区二区精品久久| 色综合久久久久无码专区| 久久久精品国产Sm最大网站| 国产精品无码久久久久久| 99久久做夜夜爱天天做精品| 国产农村妇女毛片精品久久| 国产亚洲精品美女久久久| 影音先锋女人AV鲁色资源网久久 | 久久久久青草线蕉综合超碰| 久久久噜噜噜久久中文字幕色伊伊| 久久99精品综合国产首页| 久久99精品久久久久婷婷| 无码人妻久久一区二区三区蜜桃 | 99久久精品免费看国产免费| 久久久精品一区二区三区| 久久无码人妻一区二区三区午夜| 久久精品国产亚洲AV不卡| 久久国产亚洲精品| 久久夜色精品国产亚洲| 久久九九兔免费精品6| 国产精品久久久久久五月尺| 模特私拍国产精品久久| 无码人妻久久一区二区三区蜜桃 | 人妻无码中文久久久久专区| 色综合久久无码五十路人妻| 国产精品18久久久久久vr | 亚洲综合久久久| 少妇久久久久久久久久|