NSCollectionView单元格顺序在视图更改时发生更改 [英] NSCollectionView cell order changes on view change

查看:113
本文介绍了NSCollectionView单元格顺序在视图更改时发生更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含选项卡栏设计的macOS应用程序(即:Tweetbot).有4个选项卡链接到4个不同的视图控制器.初始视图控制器(视图一)包含一个NSCollectionView,它水平显示3个单元格.

I have a macOS application that contains a tab bar design (ie: Tweetbot). There are 4 tabs that are linked to 4 different view controllers. The initial view controller (view one) contains a NSCollectionView which displays 3 cells horizontally.

这一切都很好,但是当我切换到另一个视图控制器然后又回到初始视图控制器时,收集视图的顺序会无故更改.我没有对数据源(NSMutableArray)进行任何更改,也没有添加/删除任何单元格,也没有呼叫reloadData.我不明白为什么集合视图单元格的顺序会不断变化.

This all works fine, however when I switch to another view controller and then come back to the initial view controller, the order of the collection view changes for no reason. I am not making ANY changes to the data source (which is a NSMutableArray) and I am not adding/deleting any cells, nor am I calling reloadData. I don't understand why the order of the collection view cells keep changing.

我已经进行了一些测试,可以确认我的数据源中的数据顺序完全没有改变.因此,对于收集视图而言,仅更改单元格的顺序是没有意义的.

I have done some testing and can confirm that the order of the data in my data source, does NOT change at all. So it makes no sense for the collection view, to just change the order of the cells.

我注意到的另一个奇怪的问题是,如果我将集合视图限制为2个单元格,则不会发生此问题.这使我想知道问题是否出在后台运行的某种NSCollectionView缓存方法?也许当收集视图回收一个单元格时,它使用了不正确的数据?

Another weird issue I have noticed, is that if I limit the collection view to 2 cells, this issue does not occur. This makes me wonder whether or not, the issue is down to some sort of NSCollectionView caching method that runs in the background? Perhaps when the collection view recycles a cell, it uses the incorrect data??

我尝试了许多不同的解决方案,但似乎没有任何效果.有人对我可以测试/尝试的东西有任何想法,以便找出问题所在吗?

I have tried lots of different solutions, nothing seems to work. Does anyone have any ideas of what I can test/try out, in order to find out what's wrong?

替代方案

我可以改用NSTableView,因为它支持多列(与UITableView不同).所以我可以制作一个包含3列的NSTableView.与NSCollectionView相比,这种方法在性能上是否会更差(特别是如果我想添加很多单元格的话?).

I could use NSTableView instead, because it supports multiple columns (unlike UITableView). So I could just make an NSTableView with 3 columns. Would this approach be any worse performance wise, than a NSCollectionView (especially if I wanted to add lots of cells?).

谢谢您的时间,丹.

推荐答案

我无法确定集合视图出了什么问题.因此,我最终使用了具有多个列(而不是集合视图行)的NSTableView.我将每一列设置为一行(索引为0),这使得表视图看起来与我正在使用的集合视图完全一样.

I couldn't find out what was wrong with the collection view. So I ended up using a NSTableView with multiple columns (instead of collection view rows). I set each column to have one row (index 0), which makes the table view look exactly like the collection view I was working with.

在性能方面,表视图似乎也要好得多.即使有成百上千的列,滚动/交互时它也仍然很流畅.

Performance wise the table view seems to be a lot better too. Even with hundreds of columns, it's still nice and smooth when scrolling/interacting.

这篇关于NSCollectionView单元格顺序在视图更改时发生更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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