• <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 逛奔的蝸牛 閱讀(286) 評論(0)  編輯 收藏 引用 所屬分類: Cocoa
            免费久久人人爽人人爽av| 人人狠狠综合久久亚洲婷婷| 久久久精品久久久久特色影视| 国产精品久久波多野结衣| 久久精品夜色噜噜亚洲A∨| 欧美久久久久久精选9999| 久久久久九国产精品| 久久99热这里只有精品66| 久久精品国产第一区二区三区| 久久夜色精品国产www| 亚洲va中文字幕无码久久| 久久婷婷五月综合色99啪ak| 97精品伊人久久久大香线蕉| 亚洲国产精品综合久久网络 | 色婷婷综合久久久久中文| 污污内射久久一区二区欧美日韩| 亚洲综合久久久| 精品久久久一二三区| 久久国产精品成人免费| 大香网伊人久久综合网2020| 99国产欧美久久久精品蜜芽| 久久男人AV资源网站| 久久嫩草影院免费看夜色| 99久久精品国产免看国产一区| 久久精品视频一| 欧美激情精品久久久久久| 国产成人无码精品久久久免费| 国产亚洲精品自在久久| www.久久热| 久久久久久午夜成人影院| 波多野结衣AV无码久久一区| 亚洲精品WWW久久久久久| 日韩欧美亚洲国产精品字幕久久久| 久久久久夜夜夜精品国产| a高清免费毛片久久| 久久青草国产精品一区| 久久精品视频免费| 精品久久人人妻人人做精品 | 午夜不卡888久久| 久久一区二区三区99| 久久精品亚洲男人的天堂|