• <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>

            逛奔的蝸牛

            我不聰明,但我會很努力

               ::  :: 新隨筆 ::  ::  :: 管理 ::

            #import "MyDocument.h"

            #import "Person.h"


            /**

             * 表每行的元素放在一個對象中, 所有行存放在一個NSMutableArray, 這樣好管理, 當然每列的內容可以分開存放, 但不方便.

             * 當表有多列時, (IB中選中列)要為每個列指定一個identifier, 其值為存儲的對象的屬性名稱, 當使用

             * [aTableColumn identifier], 就可以取得這一列存儲的內容是這個對象的哪一個屬性,

             * 然后使用key-value-coding([obj setValue:value forKey:@"name"], [obj valueForKey:@"name"])

             * 來取得與修改這個對象的屬性.

             *

             * 表的內容是存儲在NSTableDataSource, 只要一個類實現了下面兩個方法, 然后在界面中直接右擊表, 把其中的

             * dataSource拖動指到doc window中的這個類(文檔的直接是File's Owner, 非文檔的先建立一個NSObjectController)

             * - (int)numberOfRowsInTableView:(NSTableView*)tv 返回列的行.

             * - (id)tableView:(NSTableView*)tv objectValueForTableColumn:(NSTableColumn*)tc row:(int)rowIndex

             *

             * 如果想使一個表是可以修改的, 再實現下面的這個方法即可

             * - (void)tableView:(NSTableView*)tc setObjectValue:(id)anObject

             *      forTableColumn:(NSTableColumn*)tc row:(int)rowIndex

             *

             *

             * IBOutlet是一個宏, Interface Builder提供信息(即在其中可以看到IBOutlet修飾的變量).

             * 當你想使用一個界面元素的方法(NSTextField), 就聲明一個相關的變量為IBOutlet, 

             * 這樣, 在你的程序中就可以直接操作那個界面元素的一切.

             *

             * IBAction實際上就是void, 但是也是為了給IB提供信息, IBActon定義的方法在IB中顯示出來.

             * 事件處理函數用IBAction來定義, 如作為NSButtonaction selector.

             *

             * getter的名字為屬性的名字, setter的名字為set加上屬性的名字(此時屬性的名字的第一個字母要大寫).

             */


            @implementation MyDocument

            - (IBAction)addEmployee:(id)sender {

                Person* newEmployee = [[Person alloc] init];

                [employees addObject:newEmployee];

                [newEmployee release];

                [tableView reloadData];

            }


            - (IBAction)removeEmployee:(id)sender {

                NSIndexSet* rows = [tableView selectedRowIndexes];


                if ([rows count] == 0) {

                    NSBeep();

                    return;

                }

                

                [employees removeObjectsAtIndexes:rows];

                [tableView reloadData];

            }


            ////////////////////////////////////////////////////////////////////////////////////

            // Methods for NSTableDataSource

            ////////////////////////////////////////////////////////////////////////////////////

            - (int)numberOfRowsInTableView:(NSTableView*)tv {

                return [employees count];

            }


            - (id)tableView:(NSTableView*)tv objectValueForTableColumn:(NSTableColumn*)tc 

                        row:(int)rowIndex {

                NSString* columnIdentifier = [tc identifier];

                NSLog(@"%@", columnIdentifier);

                Person* person = [employees objectAtIndex:rowIndex];

                return [person valueForKey:columnIdentifier];

                //return nil;

            }


            - (void)tableView:(NSTableView*)tv setObjectValue:(id)anObject 

               forTableColumn:(NSTableColumn*)tc row:(int)rowIndex {

                NSString* identifier = [tc identifier]; 

                Person* employee = [employees objectAtIndex:rowIndex];

                [employee setValue:anObject forKey:identifier];

            }


            ////////////////////////////////////////////////////////////////////////////////////

            // Overrieded Methods.

            ////////////////////////////////////////////////////////////////////////////////////

            - (id)init

            {

                self = [super init];

                if (self) {

                    // Add your subclass-specific initialization here.

                    // If an error occurs here, send a [self release] message and return nil.

                    employees = [[NSMutableArray alloc] init];

                }

                

                return self;

            }


            - (void)dealloc {

                [employees release];

                [super dealloc];

            }


            - (NSString *)windowNibName

            {

                // Override returning the nib file name of the document

                // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.

                return @"MyDocument";

            }


            - (void)windowControllerDidLoadNib:(NSWindowController *) aController

            {

                [super windowControllerDidLoadNib:aController];

                // Add any code here that needs to be executed once the windowController has loaded the document's window.

            }


            - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError

            {

                // Insert code here to write your document to data of the specified type. If the given outError != NULL, ensure that you set *outError when returning nil.


                // You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.


                // For applications targeted for Panther or earlier systems, you should use the deprecated API -dataRepresentationOfType:. In this case you can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead.


                if ( outError != NULL ) {

            *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];

            }

            return nil;

            }


            - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError

            {

                // Insert code here to read your document from the given data of the specified type.  If the given outError != NULL, ensure that you set *outError when returning NO.


                // You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead. 

                

                // For applications targeted for Panther or earlier systems, you should use the deprecated API -loadDataRepresentation:ofType. In this case you can also choose to override -readFromFile:ofType: or -loadFileWrapperRepresentation:ofType: instead.

                

                if ( outError != NULL ) {

            *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];

            }

                return YES;

            }


            @end


            posted on 2008-10-04 16:47 逛奔的蝸牛 閱讀(6456) 評論(0)  編輯 收藏 引用 所屬分類: C/C++
            久久精品成人影院| 久久精品成人免费观看97| 久久精品免费一区二区| 久久久久se色偷偷亚洲精品av| 久久夜色精品国产噜噜麻豆 | 色综合色天天久久婷婷基地| 久久综合狠狠综合久久激情 | 国产精品久久久久aaaa| 国产亚洲成人久久| 精品国产青草久久久久福利| 99久久国产综合精品五月天喷水 | 久久久久99精品成人片直播| 品成人欧美大片久久国产欧美| yy6080久久| 青青热久久国产久精品| 国产精品久久久久久久久| 久久SE精品一区二区| 久久精品国产99久久久香蕉| 国产精品禁18久久久夂久| 久久亚洲精品国产精品婷婷| 亚洲国产成人久久综合一| 久久亚洲欧美国产精品| 色8激情欧美成人久久综合电| 亚洲国产精品久久久久网站| 91精品国产综合久久精品| 香蕉久久av一区二区三区| 国产成人精品综合久久久| 亚洲国产精品无码久久久久久曰 | 丰满少妇高潮惨叫久久久| 久久精品国产男包| 久久青青草原精品国产不卡| 99热精品久久只有精品| 99久久精品免费| 久久久久99精品成人片三人毛片| 四虎国产精品免费久久5151| 久久被窝电影亚洲爽爽爽| 精品久久久久久中文字幕| 色综合久久中文综合网| 久久精品无码专区免费| 亚洲国产精品成人久久蜜臀 | 久久福利青草精品资源站|