我正在尝试显示一个 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/