编辑:我们发现如果我们使用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委托中放置了断点,以查看它们是否被重复调用,但它们不是。我无法让代码通过断点停止,只是暂停它,这使我处于非符号化的土地上。