基于视图的NSTableView在插入带有动画的新行后呈现空白行 [英] View-based NSTableView renders blank rows after inserting new rows with animation

查看:290
本文介绍了基于视图的NSTableView在插入带有动画的新行后呈现空白行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于视图的 NSTableView ,我支持一个`NSMutableArray。

I have a view-based NSTableView that I'm backing with an `NSMutableArray . Periodically I go out grab some data and want to insert new rows into the table at the top.

当我这样做而没有指定动画时, insertRowsAtIndexes:withAnimation:它似乎工作正常小时结束。但是,如果我指定动画,在大约7或8个插入后,表视图开始显示发生插入的空白行。

When I do this without specifying an animation to insertRowsAtIndexes:withAnimation: it seems to work fine for hours on end. However, if I specify an animation, after about 7 or 8 inserts the table view starts to show blank rows where the inserts occurred. Scrolling down and then back up causes the new rows to render properly.

调用 insertRowsAtIndexes:withAnimation 的代码是在一个块中,而不是在主线程上运行,但我的插入发生在主队列上的dispatch_async内部,所以我不认为它与多线程相关。

The code that calls insertRowsAtIndexes:withAnimation is in a block, and not running on the main thread, but my inserts happen inside of dispatch_async on the main queue, so I dont' think it related to multithreading.

以下是一些代码... self.contents 是我的 NSMutableArray

Here is some code ... self.contents is my NSMutableArray.

 dispatch_async(dispatch_get_main_queue(), ^{
                [self.contentsTableView beginUpdates];
                if(posts.count) {
                    for(NSDictionary* dictionary in [posts reverseObjectEnumerator]) {
                        FNPost* post = [[FNPost alloc] initWithDictionary:dictionary width:self.contentsTableView.frame.size.width];
                        post.delegate = self;
                        [self.contents insertObject:post atIndex:0];
                        [self.contentsTableView insertRowsAtIndexes:[NSIndexSet indexSetWithIndex:0] withAnimation: NSTableViewAnimationSlideLeft];
                    }
                }
                [self.contentsTableView endUpdates];

            });

我困惑的一件事是Apple NSTableView insertRowsAtIndexes:withAnimation 的说明文件:

One thing I'm confused about is the part of the Apple NSTableView documentation for insertRowsAtIndexes:withAnimation that says:


表视图中的numberOfRows将自动减少
的索引计数。

The numberOfRows in the table view will automatically be decreased by the count of indexes.

意味着我的数组中的对象数量之间的关系(因此,结果 numberOfRowsInTableView:)和表视图认为它的行数。对我的想法,表视图中的行数应该等于我的数组计数,我想确保我的理解这不是问题的根本,但像我说的,如果没有指定动画,表工作正常。

I'm confused by what that statement implies about the relationship between the number of objects in my array (and hence the result of numberOfRowsInTableView:) and the number of rows the table view thinks it has. To my thinking the number of rows in the table view should equal my array count and I want to make sure that my understanding of this is not at the root of the problem but like I said, the table works fine if no animation is specified.

我在这里做明显错误吗?

Am I doing something obviously wrong here?

推荐答案

原因是在基于层的视图层次中具有NSTableView。两个superviews了,我有一个layer-backed视图。在阅读一些关于NSTableView的其他帖子显示其他错误的行为,当在支持层的层次结构中,我决定关闭IB中的图层。如果我想在我的视图之间使用CA转换,那么现在会出现表动画,因为我希望在保持一些额外状态以控制图层备份状态的情况下。

This issue turns out to be caused by having the NSTableView in a layer based view hierarchy. Two superviews up, I had a layer-backed view. After reading some other posts about NSTableView showing other errant behavior when in a layer-backed hierarchy I decided to turn off the layer in IB. Table animations now occur as I would expect at the expense of having to maintain some additional state to control the layer backing state when I want to use CA transitions between my views.

这篇关于基于视图的NSTableView在插入带有动画的新行后呈现空白行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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