具有textfield和NSPopUpButtonCell标题的基本IBAction函数问题

时间:2012-06-22 16:58:12

标签: objective-c nspopupbutton

我只是将基础知识降低到目标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:]时不允许使用占位符参数。你能为我指出正确的方向吗?

1 个答案:

答案 0 :(得分:3)

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

这就是我要做的事情:

- (IBAction)dropbox:(id)sender{
NSPopUpButtonCell *sampleCell = [sender selectedCell];
[self.word setTextValue:sampleCell.title]; 
}