隐藏显示/隐藏按钮(图基于大纲视图)
问题描述:
如何隐藏显示/隐藏按钮(编辑为扩大在这里)。即使我将它设置为空字符串,数据单元的边框也会缩小,如图所示。以前我使用的方法- (BOOL)outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:(id)item
,它隐藏显示/隐藏字符串,并完美工作。但问题是outlineview只允许扩展而不是崩溃。我想通过单击相应的父节点一次只扩展一个父节点。
答
终于解决了吧,this code帮了我。
- (NSRect)frameOfOutlineCellAtRow:(NSInteger)rowIndex
{
NSRect superFrame = [super frameOfOutlineCellAtRow:rowIndex];
// Return NSZeroRect if the row is a group row
if ([[self delegate] respondsToSelector:@selector(outlineView:isGroupItem:)]) {
if ([[self delegate] outlineView:self isGroupItem:[self itemAtRow:rowIndex]]) {
return NSZeroRect;
}
}
return superFrame;
}
+2
我为您使用其他委托方法提供了更好的解决方案。否则,您的解决方案可能会在任何时候中断,例如,如果剪切停止为您隐藏单元格。 – Dalzhim
答
使用从NSOutlineViewDelegate方法此方法:
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:(ID)项;
固定:此代码帮助我(https://code.google.com/p/sequel-pro/source/browse/trunk/Source/SPFavoritesOutlineView.m?spec=svn4025&r=4025) – user23790