NSCollectionView如何滚动到所选项 [英] NSCollectionView How to scroll to selected item

查看:1388
本文介绍了NSCollectionView如何滚动到所选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以编程方式在我的NSCollectionView中选择一个项目。

I programmatically select a item in my NSCollectionView. The item is selected as expected but the view doesn't scroll automatically to this item.

[collectionView setSelectionIndexes:[NSIndexSet indexSetWithIndex:compt]];

如何滚动到所选项目?

推荐答案

在此处查找答案 NSScrollView:确保框架可见

此代码适用于我:

NSRect selectionRect = [self.collectionView frameForItemAtIndex:[[self.collectionView selectionIndexes] firstIndex]];
[self.collectionView scrollRectToVisible:selectionRect];

这篇关于NSCollectionView如何滚动到所选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆