gpt4 book ai didi

cocoa - 使数组 Controller 成为按钮的目标

转载 作者:行者123 更新时间:2023-12-03 17:42:45 26 4
gpt4 key购买 nike

我正在研究 NSArrayController 上的 COCOA PROGRAMMING FOR MAC OS X (3RD EDITION) 的一章,它告诉我:

按住 Control 键并拖动,使阵列 Controller 成为“添加新员工”按钮的目标。设置要添加的操作:

但是,当我拖动数组 Controller 时,它不会突出显示,因此我没有得到目标选项。

如何在新的 XCode 中正确执行此操作

full size image

文档.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

文档.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

人.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

最佳答案

伙计..你在IB中做错了。这是错误的 -

enter image description here

这些条目应该在数组 Controller 的属性检查器中进行 -

enter image description here

一旦你纠正它,你将能够正确设置目标:)

关于cocoa - 使数组 Controller 成为按钮的目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8108489/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com