• <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://m.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无码专区桃色| 久久精品国产乱子伦| 久久久久久久尹人综合网亚洲| 亚洲国产精品久久久久婷婷软件 | 国内精品伊人久久久久AV影院| 777米奇久久最新地址| 久久影院午夜理论片无码| 亚洲国产精品一区二区久久hs| 国产成人AV综合久久| 亚洲国产精品一区二区久久hs| 久久成人永久免费播放| 久久久一本精品99久久精品66| 久久亚洲AV永久无码精品| 国产91色综合久久免费| 热99RE久久精品这里都是精品免费 | 色青青草原桃花久久综合| 97久久久精品综合88久久| 2021国内久久精品| 久久精品国产一区二区 | 麻豆av久久av盛宴av| 国产精品欧美亚洲韩国日本久久| 国色天香久久久久久久小说| 久久精品夜色噜噜亚洲A∨| 国产91色综合久久免费分享| 久久99久国产麻精品66| 亚洲第一永久AV网站久久精品男人的天堂AV| 欧美牲交A欧牲交aⅴ久久| 思思久久精品在热线热| 亚洲国产精品久久久天堂| 色综合久久天天综合| 亚洲va中文字幕无码久久不卡| 久久精品国产精品亚洲人人| 久久久国产乱子伦精品作者| 国产精品嫩草影院久久| 狠狠色丁香婷婷综合久久来 | 99国产精品久久久久久久成人热| 欧美亚洲日本久久精品| 欧美精品丝袜久久久中文字幕 | 青青青青久久精品国产h| 久久精品国产亚洲综合色| 99久久无色码中文字幕|