0

我只是在了解目标 c 的基础知识。我想创建一个文本字段,其字符串与我选择的 Dropbox 单元格的标题相同。我有:

- (IBAction)dropbox:(id)sender{
NSPopUpButtonCell *sampleCell = [sender selectedCell];
[self setWord:@"%@",sampleCell.title]; 

[sampleCell release];
}

word 被声明为

@property (readwrite, nonatomic, retain) IBOutlet NSTextField *word;
@synthesize word = _word;

显然我在使用 [self setWord:] 时不允许使用占位符参数。你能为我指出正确的方向吗?

4

1 回答 1

3

首先,您没有获得所有权,sampleCell因此您不应该发布它。这将触发异常。此外,您将 NSTextField 设置为字符串。

这就是我要做的:

- (IBAction)dropbox:(id)sender{
NSPopUpButtonCell *sampleCell = [sender selectedCell];
[self.word setTextValue:sampleCell.title]; 
}
于 2012-06-22T17:06:20.783 回答