• <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 逛奔的蝸牛 閱讀(6461) 評論(0)  編輯 收藏 引用 所屬分類: C/C++
            成人国内精品久久久久影院| 热久久这里只有精品| 精品一二三区久久aaa片| 欧美一区二区三区久久综| 热久久国产精品| 亚洲精品无码成人片久久| 久久99热精品| 久久久精品国产sm调教网站| 91精品国产91久久久久久| 亚洲香蕉网久久综合影视| 久久高清一级毛片| 久久精品国产一区二区三区日韩| 日本久久久久久久久久| 91精品国产91热久久久久福利| 久久久无码精品亚洲日韩京东传媒 | 一本久久知道综合久久| 亚洲欧美精品伊人久久| 久久精品中文闷骚内射| 中文字幕久久亚洲一区| 久久精品国产WWW456C0M| 人妻少妇久久中文字幕| 久久伊人五月丁香狠狠色| 久久精品成人免费国产片小草| a高清免费毛片久久| 99国产精品久久久久久久成人热| 青草久久久国产线免观| 久久久噜噜噜久久| 久久丝袜精品中文字幕| 狠狠精品久久久无码中文字幕| 久久精品国产亚洲沈樵| 99久久99这里只有免费费精品| 伊人久久大香线蕉av不卡| 久久精品国产久精国产果冻传媒| 思思久久99热只有频精品66| 亚洲欧美另类日本久久国产真实乱对白| 一本大道加勒比久久综合| 国产—久久香蕉国产线看观看| 国产 亚洲 欧美 另类 久久| 国产福利电影一区二区三区久久老子无码午夜伦不 | 精品乱码久久久久久夜夜嗨| 国产无套内射久久久国产|