NSOutlineViewoutlineViewSelectionDidChange

发布于 2024-12-06 04:12:47 字数 256 浏览 0 评论 0原文

我的 NSOutlineView OutlineViewSelectionDidChange 方法将不会被调用。 我将 NSOutlineViews 委托设置为存在其他方法的类

- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item

。但是在选择项目时不会调用outlineViewSelectionDidChange。 有人有想法吗?

my NSOutlineView outlineViewSelectionDidChange method will not be called.
I set set the NSOutlineViews delegate to the class where the other methods such as

- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item

exist. But outlineViewSelectionDidChange will not be called on selecting an item.
Does anybody has an idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浴红衣 2024-12-13 04:12:47

该通知有点奇怪,因为它不会自动转发给代表。尝试在初始化代码中添加显式注册,如下例所示:

- (void)windowControllerDidLoadNib:(NSWindowController *)aController;
{
    [super windowControllerDidLoadNib:aController];
    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
    [center addObserver:self
               selector:@selector(outlineViewSelectionDidChange:)
                   name:@"NSOutlineViewSelectionDidChangeNotification"
                 object:outlineView];
}

This notification is a bit odd, in that it is not automatically forwarded to delegates. Try adding an explicit registration to your initialization code, like this example:

- (void)windowControllerDidLoadNib:(NSWindowController *)aController;
{
    [super windowControllerDidLoadNib:aController];
    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
    [center addObserver:self
               selector:@selector(outlineViewSelectionDidChange:)
                   name:@"NSOutlineViewSelectionDidChangeNotification"
                 object:outlineView];
}
ぽ尐不点ル 2024-12-13 04:12:47

好的,
同时我发现“NSOutlineViewSelectionDidChangeNotification”只会在通知对象内抛出。所以我必须对 NSOutlineView 进行子类化以捕获通知并将其传递给我需要的对象。

Okay,
meanwhile i figured out that the "NSOutlineViewSelectionDidChangeNotification" will be thrown only within the notification object. So i had to subclass my NSOutlineView to catch the notification and pass it to the object where i need it.

薄情伤 2024-12-13 04:12:47

您自己的视图需要符合 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 类中。

-(void)outlineViewSelectionDidChange:(NSNotification *)notification {
    NSLog(@"selection did change");
}

Your own view needs to conform to the NSOutlineViewDelegate protocol like so..

@interface MyOutlineViewController : NSView <NSOutlineViewDataSource,NSOutlineViewDelegate> {
    IBOutlet NSOutlineView *myoutlineview;
}
@end

you will have this methods in your implementation

-(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;

where you setup your outlineview.
When loading this view -(void)viewDidLoad gets called and your predefined nib/xib file or your manual call will set your datasource to fill it depending on your logic.

Now in your -(void)viewDidLoad your myoutlineview needs to set its own delegate with

[myoutlineview setDelegate:self];

so your own View may know where to call its notification methods triggerd from selections and so on. So you can place your notification logic inside the same View class conforming to this protocol.

-(void)outlineViewSelectionDidChange:(NSNotification *)notification {
    NSLog(@"selection did change");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文