2011-11-12 29 views
0

我通過COCOA PROGRAMMING FOR MAC OS X (3RD EDITION)NSArrayController一章工作的目標,它告訴我:形成陣列控制器按鈕

按住Ctrl拖動,使陣列控制器成爲添加新的員工按鈕的目標。設置要添加的動作:

但是,當我拖動array controller它不會突出顯示,所以我沒有目標選項。

我怎麼做這個正確的新XCode

full size image

document.h:

// 
// Document.h 
// RaiseMan 
// 
// Created by user on 11/12/11. 
// Copyright (c) 2011 __MyCompanyName__. All rights reserved. 
// 

#import <Cocoa/Cocoa.h> 

@interface Document : NSDocument 
{ 
    NSMutableArray *employees; 
} 

@end 

document.m:

// 
// Document.m 
// RaiseMan 
// 
// Created by user on 11/12/11. 
// Copyright (c) 2011 __MyCompanyName__. All rights reserved. 
// 

#import "Document.h" 

@implementation Document 

- (id)init 
{ 
    self = [super init]; 
    if (self) { 
     employees = [[NSMutableArray alloc] init]; 
    } 
    return self; 
} 

- (void)dealloc 
{ 
    [self setEmployees:nil]; 
    [super dealloc]; 
} 


-(void)setEmployees:(NSMutableArray *)a 
{ 
    //this is an unusual setter method we are goign to ad a lot of smarts in the next chapter 
    if (a == employees) 
     return; 
    [a retain]; 
    [employees release]; 
    employees = a; 
} 

- (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 @"Document"; 
} 

- (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 outError != NULL, ensure that you create and set an appropriate error when returning nil. 
    You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead. 
    */ 
    NSException *exception = [NSException exceptionWithName:@"UnimplementedMethod" reason:[NSString stringWithFormat:@"%@ is unimplemented", NSStringFromSelector(_cmd)] userInfo:nil]; 
    @throw exception; 
    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 outError != NULL, ensure that you create and set an appropriate error when returning NO. 
    You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead. 
    If you override either of these, you should also override -isEntireFileLoaded to return NO if the contents are lazily loaded. 
    */ 
    NSException *exception = [NSException exceptionWithName:@"UnimplementedMethod" reason:[NSString stringWithFormat:@"%@ is unimplemented", NSStringFromSelector(_cmd)] userInfo:nil]; 
    @throw exception; 
    return YES; 
} 

+ (BOOL)autosavesInPlace 
{ 
    return YES; 
} 


    - (void)setEmployees:(NSMutableArray *)a; 

    @end 

person.h:

// 
// Person.h 
// RaiseMan 
// 
// Created by user on 11/12/11. 
// Copyright (c) 2011 __MyCompanyName__. All rights reserved. 
// 

#import <Foundation/Foundation.h> 

@interface Person : NSObject 
{ 
    NSString *personName; 
    float expectedRaise; 
} 

@property (readwrite, copy) NSString *personName; 
@property (readwrite) float expectedRaise; 

@end 

person.m:

// 
// Person.m 
// RaiseMan 
// 
// Created by user on 11/12/11. 
// Copyright (c) 2011 __MyCompanyName__. All rights reserved. 
// 

#import "Person.h" 

@implementation Person 

- (id) init 
{ 
    self = [super init]; 
    expectedRaise = 5.0; 
    personName = @"New Person"; 
    return self;  
} 

- (void)dealloc 
{ 
    [personName release]; 
    [super dealloc]; 
} 

@synthesize personName; 
@synthesize expectedRaise; 

@end 
+0

你還可以在某個地方上傳你的代碼......這樣我們可以檢查嗎? – Devarshi

+0

添加完整的代碼 – ian

+0

你的代碼看起來不錯...如果你有投遞箱或其他文件共享服務的帳戶,你可以上傳它,以便我們可以重現你的問題,並解決它? – Devarshi

回答

2

哥們..你做錯了在IB。這是錯誤的 -

enter image description here

這些條目應在屬性檢查器中進行的陣列控制器 -

enter image description here

一旦你改正,你就能夠正確地設定目標:)

+0

是的,其實我抓住了,並修復它,它仍然不工作... – ian

+0

你仍然無法設定目標?請檢查並驗證其他綁定! – Devarshi

+0

是的陣列對象只是不會突出顯示,當我嘗試以它爲目標。 – ian