• <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 逛奔的蝸牛 閱讀(289) 評論(0)  編輯 收藏 引用 所屬分類: Cocoa
            色欲久久久天天天综合网| 久久久久无码国产精品不卡| 亚洲色欲久久久久综合网| 亚洲精品tv久久久久| 久久亚洲国产成人精品性色| 久久国产高清字幕中文| 狠狠人妻久久久久久综合蜜桃| 三级片免费观看久久| 亚洲AV无码久久精品色欲| 久久精品国内一区二区三区 | 久久精品国产91久久综合麻豆自制 | 亚洲人成伊人成综合网久久久| 性欧美大战久久久久久久久| 四虎国产精品免费久久5151| 亚洲精品无码久久毛片| 77777亚洲午夜久久多喷| 亚洲性久久久影院| 2020最新久久久视精品爱| 久久精品无码一区二区WWW| 97精品国产97久久久久久免费| 久久久久国产精品人妻| 久久久综合九色合综国产| 狠狠色狠狠色综合久久| 久久99精品国产麻豆婷婷| 精品熟女少妇a∨免费久久| 久久福利资源国产精品999| 国产呻吟久久久久久久92| 人妻无码久久一区二区三区免费| 久久免费观看视频| 久久e热在这里只有国产中文精品99| 久久精品国产亚洲av水果派 | 无遮挡粉嫩小泬久久久久久久| 久久久不卡国产精品一区二区| 97精品国产91久久久久久| 久久夜色精品国产网站| 中文字幕无码精品亚洲资源网久久| 久久久久国产一区二区三区| 国内精品久久久久久久亚洲| 99精品国产在热久久无毒不卡| 人妻精品久久久久中文字幕69| 合区精品久久久中文字幕一区|