NSTableView隐藏按钮
我有点卡住了,似乎无法从苹果文档中解决这个问题。NSTableView隐藏按钮
我在NSTable列中包含两个按钮,包含在NSTableCellView中。
我想在代码中隐藏该按钮取决于该行中对象的值。
获取值是好的,但我不能解决如何针对特定的按钮,我不能将它绑定到一个插座,因为它是在一个表内。我已经尝试了下面的代码,但这只是隐藏了整个NSTableCellView而不是特定的按钮,我也尝试将标识符更改为按钮,但似乎也这样做。
if(selectedTweet.imageURL){
NSButton *imageButton = [tableView makeViewWithIdentifier:@"secondButtons" owner:self];
[imageButton setHidden:NO];
return imageButton;
} else {
NSButton *imageButton = [tableView makeViewWithIdentifier:@"secondButtons" owner:self];
[imageButton setHidden:YES];
return imageButton;
}
这显然比我做它更简单?非常感谢。
感谢
加雷思
如果使用CocoaBindings来填充表,你可以将按钮的“隐藏”属性绑定到Table Cell View/objectValue.imageURL
并使用NSIsNil
值转换。根本不需要代码。
如果您使用的是老式的数据源,事情会变得更加复杂。在这种情况下,你可以在你的对象中有一个imageButton属性,并将其设置在NSTableViewDelegate的方法- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
中。
神牛粪这么简单,谢谢你,也解决了我遇到的其他一些问题。传说! –
从你的代码我看到你正试图创建一个NSTableCellView的按钮可见/隐藏取决于条件。你试着在IB上有两个不同的预定义的NSTableCellView,如“secondButtonsWithButton”和“secondButtonsWithoutButton”,并调用每个必要时 ? – CoderPug