• <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 逛奔的蝸牛 閱讀(290) 評論(0)  編輯 收藏 引用 所屬分類: Cocoa
            99久久夜色精品国产网站| 久久久久久久久久久久中文字幕| 久久久国产精品网站| 99久久精品久久久久久清纯| 噜噜噜色噜噜噜久久| 99热成人精品热久久669| 久久精品无码一区二区app| 免费无码国产欧美久久18| 国产成人久久激情91| 久久国语露脸国产精品电影| 伊人久久大香线焦综合四虎| 亚洲av成人无码久久精品| 久久99精品国产麻豆蜜芽| 1000部精品久久久久久久久| 久久中文精品无码中文字幕| 久久99热狠狠色精品一区| 99久久精品免费看国产一区二区三区 | 久久精品国产99国产精偷| 国内精品久久久久久久久电影网| 亚洲国产成人久久综合碰碰动漫3d | 亚洲а∨天堂久久精品9966| 色综合久久中文色婷婷| 国内精品久久久久久久97牛牛| 一本色道久久综合| 亚洲精品成人网久久久久久| 精品欧美一区二区三区久久久| 久久精品一区二区三区不卡| 韩国免费A级毛片久久| 日日噜噜夜夜狠狠久久丁香五月| 伊人久久无码精品中文字幕| 日本亚洲色大成网站WWW久久| 久久国产福利免费| 久久99热这里只有精品国产| 久久夜色tv网站| 国产精品成人99久久久久 | 欧美一区二区精品久久| 久久99国产亚洲高清观看首页| 狠狠狠色丁香婷婷综合久久俺| 国产成人久久AV免费| 久久久久夜夜夜精品国产| 久久综合九色综合精品|