我的NSOutlineView outlineViewSelectionDidChange方法不会被调用。我将NSOutlineViews委托设置为这样的类,其他方法
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item存在。但不会在选择项时调用outlineViewSelectionDidChange。有谁有主意吗?
发布于 2011-09-23 01:34:12
这个通知有点奇怪,因为它不会自动转发给代表。尝试向初始化代码添加显式注册,如下例所示:
- (void)windowControllerDidLoadNib:(NSWindowController *)aController;
{
[super windowControllerDidLoadNib:aController];
NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(outlineViewSelectionDidChange:)
name:@"NSOutlineViewSelectionDidChangeNotification"
object:outlineView];
}发布于 2011-09-23 23:00:12
好的,同时我发现"NSOutlineViewSelectionDidChangeNotification“只会在通知对象中抛出。因此,我不得不继承我的NSOutlineView来捕获通知,并将其传递给我需要它的对象。
发布于 2015-09-15 08:35:17
您自己的视图需要符合NSOutlineViewDelegate协议,如下所示。
@interface MyOutlineViewController : NSView <NSOutlineViewDataSource,NSOutlineViewDelegate> {
IBOutlet NSOutlineView *myoutlineview;
}
@end您将在您的实现中使用此方法
-(NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item;
-(BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item;
-(id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item;
-(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item;在那里设置你的大纲视图。加载此视图时,将调用-(void)viewDidLoad,预定义的nib/xib文件或手动调用将根据您的逻辑将数据源设置为填充它。
现在,在您的-(void)viewDidLoad中,您的myoutlineview需要使用
[myoutlineview setDelegate:self];因此,您自己的View可能知道在哪里调用它的通知方法、triggerd from selections等等。因此,您可以将通知逻辑放在符合此协议的同一个View类中。
-(void)outlineViewSelectionDidChange:(NSNotification *)notification {
NSLog(@"selection did change");
}https://stackoverflow.com/questions/7518917
复制相似问题