cocoa - NSTableView rowViewAtRow : always returning nil

标签 cocoa nstableview

我正在尝试显示一个 NSPopover,其中包含 NSTableView 的选定行的附加信息。为此,我需要获取对所选行的 View 表示的引用,以便我可以将弹出框“附加”到它:

    NSInteger row = [[self membersTableView] selectedRow];
    NSTableRowView *aView = [[self membersTableView] rowViewAtRow: row makeIfNecessary: YES];
    [self setQuickLookPopoverController: [QuickLookPopoverController showPopoverFor: anObject at: aView]];

在上面,aView的结果总是nil。根据Apple documentation ,这是在给定选定行的情况下获取 View 对象的方法。尤其是讨论的最后一句有点奇怪:

Discussion This method will first attempt to return a currently displayed view in the visible area. If there is no visible view, and makeIfNecessary is YES, a prepared temporary view is returned. If makeIfNecessary is NO, and the view is not visible, nil will be returned.

In general, makeIfNecessary should be YES if you require a resulting view, and NO if you only want to update properties on a view only if it is available (generally this means it is visible).

An exception will be thrown if row is not within the numberOfRows. The returned result should generally not be held onto for longer than the current run loop cycle. It is better to call rowViewAtRow:makeIfNecessary: whenever a view is required..

为什么这个方法总是返回nil?

最佳答案

解决了。我使用 NSTableView 的方法 (NSRect) rectOfRow: (NSInteger) rowIndex 它将给出所需行的框架。

关于cocoa - NSTableView rowViewAtRow : always returning nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9087672/

相关文章:

css - Cocoa webview UserAgent "webkit-legacy"问题

objective-c - OSX NSTableView insertRowAtIndexes

drag-and-drop - 使用 NSTableView 作为拖动源的自定义拖动图像

c++ - 将即时任务添加到 `CFRunLoop` 的最简单方法?

objective-c - 重新加载 NSTableView 数据不起作用

macos - NSTextfield NSPopover 的透明背景

objective-c - 在 NSTableView 中,如何根据项目的选择对项目进行排序?

xcode - 设置 osx 的 map 以及用户当前位置

objective-c - cocoa:知道应用程序图标在 Dock 中的位置

macos - UCKeyTranslate 对于键盘上的非 ascii 键返回垃圾信息