当还没有内容时,我想继承 NSOutlineView 以在其中间显示一个标签。很像 XCode 中的检查器:
显然我不能使用委托方法,因为我将其作为子类来实现,并且在使用此类时我必须能够将委托设置为其他东西。
除了 bounds 属性的变化,我没有发现任何可以观察到的通知,但这不是很可靠。
当还没有内容时,我想继承 NSOutlineView 以在其中间显示一个标签。很像 XCode 中的检查器:
显然我不能使用委托方法,因为我将其作为子类来实现,并且在使用此类时我必须能够将委托设置为其他东西。
除了 bounds 属性的变化,我没有发现任何可以观察到的通知,但这不是很可靠。
我最终覆盖了几种NSOutlineView
注入代码的方法。这不是一个非常优雅的解决方案,但它确实有效。如果有人有更好的解决方案,请告诉我,我可能会接受您的回答。
- (void)updateEmptyLabelVisibility {
int r = [[self dataSource] outlineView:self numberOfChildrenOfItem:nil];
BOOL hasRows = r > 0;
_emptyLabel.hidden = hasRows;
}
- (void)reloadItem:(id)item {
[super reloadItem:item];
[self updateEmptyLabelVisibility];
}
- (void)reloadData {
[super reloadData];
[self updateEmptyLabelVisibility];
}
- (void)awakeFromNib {
[super awakeFromNib];
[self updateEmptyLabelVisibility];
}
- (void)endUpdates {
[super endUpdates];
[self updateEmptyLabelVisibility];
}