• <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
            久久99热这里只有精品国产| 久久久精品人妻一区二区三区蜜桃 | 久久精品中文无码资源站| 精品国产乱码久久久久久人妻 | 99久久夜色精品国产网站| 久久精品亚洲一区二区三区浴池 | 久久国产免费直播| 成人亚洲欧美久久久久| 亚洲国产精品无码久久久不卡| 996久久国产精品线观看| 色偷偷88欧美精品久久久| 久久综合香蕉国产蜜臀AV| 久久久久人妻一区精品| 久久久无码精品亚洲日韩按摩 | 国内精品伊人久久久久妇| 精品久久久久久久无码 | 久久偷看各类wc女厕嘘嘘| 久久久久亚洲AV无码去区首| 精品久久人妻av中文字幕| 久久精品综合网| 久久婷婷五月综合97色直播| 亚洲国产精品久久66| 一本久久a久久精品vr综合| 久久久亚洲精品蜜桃臀| 国产—久久香蕉国产线看观看| 久久99亚洲网美利坚合众国| 中文字幕久久精品| 要久久爱在线免费观看| 久久久久综合中文字幕| 国产激情久久久久影院小草| 精品久久久久久亚洲| 韩国免费A级毛片久久| 少妇久久久久久被弄高潮| 亚洲国产精品无码久久久不卡| 久久91精品国产91| 伊人久久大香线蕉av一区| 国产美女亚洲精品久久久综合| 国产激情久久久久久熟女老人| 成人综合久久精品色婷婷 | 99久久国产主播综合精品| 日本三级久久网|