代码之家  ›  专栏  ›  技术社区  ›  Redwood

如何使用nsbrowser中选定单元格的路径更新nspathControl

  •  5
  • Redwood  · 技术社区  · 17 年前

    我需要在nsbrowser中使用当前选定的路径更新nspathcontrol,但在从nsbrowser更改路径时,我很难找到获取通知的方法。实现这一点的理想方法只是在nsbrowser中观察路径密钥路径,但这使得kvo只能观察设置 <key> 方法返回空消息且不更新(setpath返回bool success值)。

    我还尝试观察selectedcell键路径,但是当选择发生变化时,我不会收到通知。

    有没有其他明显的方法可以做到这一点?

    3 回复  |  直到 13 年前
        1
  •  7
  •   Redwood    17 年前

    Rob Keniger在 Cocoa Dev :

    你看过simplebrowser吗 示例在/developer/examples?它 显示如何获取当前所选内容 当用户更改时, 基本上只需设置 nsbrowser的操作。

    这确实是解决问题的方法。只要实现一个-(void)broswerclicked:方法(包括在接口生成器中对其进行映射),每当该方法中的选择发生更改时,您都可以使用希望发生的任何操作,例如。

    - (void)browserClicked:(id)browser {
        self.pathToSelectedCell = [browser path]; // NSPathControl is bound to pathToSelectedCell
    }
    
        2
  •  0
  •   Marc Charbonneau    17 年前

    我刚签入了ib,看起来nsbrowser有一个选择索引路径绑定(nsindepath对象的数组),您可以用kvo监视它。这很奇怪,但我在文件中没有看到任何提到过,所以你可能需要做一些研究,看看这是你应该使用还是不应该使用的东西,即使它看起来有效。如果是这样,在kvo观察方法中,您将找到浏览器的当前路径,并将其转换为路径控件可以使用的nsurl。

    如果这不起作用,还有委托方法 - (BOOL)browser:(NSBrowser *)sender selectRow:(NSInteger)row inColumn:(NSInteger)column - (BOOL)browser:(NSBrowser *)sender selectCellWithString:(NSString *)title inColumn:(NSInteger)column .

        3
  •  0
  •   matt    13 年前

    从10.6开始,可以通过如下使用委托回调来确定选择了哪些项:

    - (NSIndexSet *)browser:(NSBrowser *)browser selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes inColumn:(NSInteger)column
    {
        NSLog(@"New first item of the new selection is at index %@", [proposedSelectionIndexes firstIndex]);
        // Do something with the selected index or indicies
        return proposedSelectionIndexes; // Allow the selection to occur by not changing this
    }