如何使NSTableView不重用TableCellViews [英] How to make NSTableView not reuse TableCellViews

查看:1060
本文介绍了如何使NSTableView不重用TableCellViews的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的基于视图的NSTableview不重用以前生成的TableCellViews滚动出来的范围。我想这将是可能的UITableView通过覆盖dequeueReusableCellWithIdentifier:返回nil。 Ist有类似的解决方案NSTableView?



-



我的背景:我有一个相当复杂的基于视图-tableView以通常的方式绑定到ManagedObjects(即table-content,-selection和-sortdescriptor被绑定到一个arraycontroller,并且tableCellView元素绑定到objectValue)。



该表有大约20列,但最多有400行。滚动真的很慢,但时间分析表明没有单一的慢度存在(最大的单一方法 - 调用花费大约5%的时间)。在缓存我的ManagedObject的派生/自定义属性而没有很多性能提升后,我现在试图缓存视图(避免在视图进入范围时频繁重新绑定tablecellViews)。



我现在尝试的是不绑定表内容,而是使用NSDatasource协议获取我的意见。其中有

   - (NSView *)tableView: row 

我想返回缓存的TableCellViews否则我通过

创建一个新的

  [self.table makeViewWithIdentifier:... owner:self]; 

由于makeViewWithIdentifier可能返回已经缓存的视图,所以表格内容被错误



这种方法的性能明显更好...



-

$ b $

解决方案

在你的tableView中:viewForTableColumn:实现将返回的视图上的.identifier设置为nil。这将阻止表缓存它。然后,您可以管理自己的缓存。 FWIW,你不必甚至使用makeViewWithIdentifier:at all;你可以从头开始手动创建视图,而不是使用该方法(从NIB加载预设置视图)。



但是,如果你有性能问题,最好通过查看什么是缓慢的和为什么解决这些。你没有提供信息为什么它是慢的,所以很难说什么。 20列是很多。您可以通过使用canDrawSubviewsIntoLayer,在NSTableCellView或NSTableRowView尝试减少您的图层计数,可能会获得更好的性能。但是,这样做有很多注意事项和事情需要注意。



corbin


I would like my view-based-NSTableview to not reuse previously generated TableCellViews that are scrolled out of scope. I figure that this would be possible with UITableView by overwriting dequeueReusableCellWithIdentifier: to return nil. Ist there is similar solution for NSTableView?

-

My Background: I have a quite complex view-based-tableView bound to ManagedObjects in the usual way (i.e. table-content, -selection and -sortdescriptor are bound to an arraycontroller and the tableCellView-elements bind to the objectValue).

The table has about 20 columns but at most 400 rows. Scrolling is really slow, but time-profiling indicates that no single source of slowness exists (largest single method-call takes about 5% of time). After caching the derived/custom properties of my ManagedObject without much performance-boost, i'm now trying to cache the views (to avoid the frequent rebind of the tablecellViews when a view comes into scope).

What i'm trying at the moment is to not bind the table-content, but to get my views using the NSDatasource-protocol. There in

-(NSView*) tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row

i would like to return cached TableCellViews if they exist. Otherwise i create a new one via

[self.table makeViewWithIdentifier:... owner:self];

Since makeViewWithIdentifier may return views that are already cached by me, the table-content gets messed up with wrong cells.

Performance is significantly better with this approach...

-

Other ideas on making scrolling more performant are also appriciated.

解决方案

In your tableView:viewForTableColumn: implementation set the .identifier on the returned view to nil. That will prevent the table from caching it. You could then manage your own cache. FWIW, you don't have to even use makeViewWithIdentifier: at all; you can just manually create your views from scratch, instead of using that method (which loads the pre-setup views form the NIB).

However, if you are having performance problems, it would be better to address those by looking at what is slow and why. You didn't provide information on why it is slow, so it is hard to say what to do. 20 columns is a lot. You might get better performance by attempting to reduce your layer count by using canDrawSubviewsIntoLayer, on the NSTableCellView, or the NSTableRowView. But there are lots of caveats and things to be aware of when doing this.

corbin

这篇关于如何使NSTableView不重用TableCellViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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