View-based NSTableView displays blank lines after inserting new lines with animation

I have a view based NSTableView that I support with `NSMutableArray. Periodically, I remove some data and want to insert new rows in the table at the top.

When I do this without pointing out the animation on insertRowsAtIndexes:withAnimation: it seems to work fine for several hours in a row. However, if I specify an animation, after 7 or 8 inserts, the table view starts showing empty rows where the inserts occurred. Scrolling down and then backing up correctly renders newlines.

The code that calls insertRowsAtIndexes:withAnimation is in the block and does not work in the main thread, but my inserts happen inside dispatch_async in the main queue, so I don't think this is multithreaded.

Here is the 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]; }); 

One thing I am confused about is the part of Apple's NSTableView documentation for insertRowsAtIndexes:withAnimation , which states:

The number ofOfRows in the table view will automatically be reduced by the number of indexes.

I am confused by what is meant in this statement about the relationship between the number of objects in my array (and therefore the result of numberOfRowsInTableView: , and the number of rows that the table thinks have tables. In my opinion, the number of rows in the table view should be equal to my array count, and I want to make sure that my understanding of this is not at the root of the problem, but, as I said, the table works fine if no animation is specified.

Am I doing something obviously wrong here?

+3
source share
1 answer

This problem is caused by the presence of an NSTableView in the layer-based view hierarchy. Two supervisors, I had a layer with support. After reading some other NSTableView posts showing other erroneous behavior when in a hierarchy with layer support, I decided to disable the layer in IB. Table animations now happen, as I would expect, due to the need to maintain some additional state to manage the level support state when I want to use CA transitions between my views.

+1
source

All Articles