我以编程方式在我的 NSCollectionView 中选择一个项目。该项目已按预期选择,但 View 不会自动滚动到该项目。
[collectionView setSelectionIndexes:[NSIndexSet indexSetWithIndex:compt]];
如何滚动到所选项目?
最佳答案
在这里找到答案NSScrollView: Make sure frame is visible
这段代码对我有用:
NSRect selectionRect = [self.collectionView frameForItemAtIndex:[[self.collectionView selectionIndexes] firstIndex]];
[self.collectionView scrollRectToVisible:selectionRect];
关于objective-c - NSCollectionView 如何滚动到所选项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18541159/