0

编辑: 我们发现如果我们使用由 Interface Builder 创建的 UICollectionView,则不会发生这种情况。显然,他们正在做一些我们在实例化期间没有做的事情。这是我们的例行公事:

UICollectionViewFlowLayout* layout = [UICollectionViewFlowLayout alloc];
[layout setScrollDirection:UICollectionViewScrollDirectionVertical];
colView = [[UICollectionView alloc] initWithFrame:f collectionViewLayout:layout];
[colView setBackgroundColor:[UIColor blackColor]];
[colView setDataSource:self];
[colView setDelegate:self];
[colView setCanCancelContentTouches:NO];
[colView setClipsToBounds:NO];
[colView registerNib:[UINib nibWithNibName:@"CTTextViewCell" bundle:nil] forCellWithReuseIdentifier:@"LabelCell"];
[self.view colView];

我们缺少什么才能正确删除/插入工作?

=================

我们使用以编程方式生成的 UICollectionView 看到了一个非常奇怪的内存问题(尽管我怀疑这很重要)。如果我们调用其中任何一个:

reloadItemsAtIndexPaths:
deleteItemsAtIndexPaths: 
insertItemsAtIndexPaths:  

系统进入无限循环并搅动内存,直到崩溃。

奇怪的是,调用 reloadData 不会导致这个问题。暂停执行显示以下内容,根据您按下暂停的时间,此堆栈上方的各种调用。

4   0x32423d86 in -[UICollectionView _endItemAnimations] () 
5   0x000bc174 in -[ASCollectionViewController collectionView:didSelectItemAtIndexPath:] at /Users/rwitman/Documents/git/airshow/photoChuck/Source/ASCollectionViewController.m:248 
6   0x3247ea96 in -[UICollectionView _userSelectItemAtIndexPath:] () 
7   0x3247e7bc in -[UICollectionView touchesEnded:withEvent:] () 
8   0x323e88da in forwardTouchMethod () 
9   0x323e88da in forwardTouchMethod () 
10  0x32259380 in _UIGestureRecognizerUpdate () 
11  0x322911b4 in -[UIWindow _sendGesturesForEvent:] () 
12  0x32290b62 in -[UIWindow sendEvent:] () 
13  0x32265f58 in -[UIApplication sendEvent:] () 
14  0x32264746 in _UIApplicationHandleEventQueue () 
15  0x2faa6f26 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ () 
16  0x2faa63ee in __CFRunLoopDoSources0 () 
17  0x2faa4bde in __CFRunLoopRun () 
18  0x2fa0f540 in CFRunLoopRunSpecific () 
19  0x2fa0f322 in CFRunLoopRunInMode () 
20  0x347462ea in GSEventRunModal () 
21  0x322c61e4 in UIApplicationMain ()  

热门电话可以是:

0   0x2fa20a2e in -[__NSFastEnumerationEnumerator nextObject] () 
0   0x2fa1ac76 in -[__NSDictionaryM countByEnumeratingWithState:objects:count:] () 
0   0x39de1898 in objc_object::sidetable_retain() () 
0   0x3a3acd2a in tiny_malloc_from_free_list ()

有什么想法吗?

附加 的一个例子是这个从集合视图中删除元素的相当简单的代码

// remove our asset from the local array that provides the data source for the collection view
[elementArray removeObjectAtIndex:index];

// now delete it visually
[colView deleteItemsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForItem:index inSection:0], nil]];

我还在各种 dataSource 委托中放置了断点,以查看它们是否被重复调用,但它们不是。我无法让代码通过断点停止,只能暂停它,这让我处于非符号化领域。

4

0 回答 0