【问题标题】:UICollectionView crashes when deleting section删除部分时 UICollectionView 崩溃
【发布时间】:2013-10-25 14:30:17
【问题描述】:

使用此代码时

  - (void)actionSheet:(UIActionSheet *)actionSheet 
             clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        if (buttonIndex == 0) {

            [self removeCompany:companySelectedInActionSheet]; 

            NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:
                          indexPathSelectedInActionSheet.section];
            NSLog(@"IndexSet to delete from collection view: %@",indexSet);
            [self.collectionView deleteSections:indexSet]; 
        }
    }

我的应用程序有时会崩溃(10% 的时间)并出现此错误:

*** Assertion failure in -[UICollectionView _endItemAnimations], /SourceCache/UIKit_Sim/UIKit-2903.2/UICollectionView.m:3700

对可能出现的问题有什么想法吗?

在删除之前显示的操作表是否存在潜在问题?

在删除收藏视图部分之前是否需要手动关闭它?

【问题讨论】:

  • 可能是您的UICollectionViewDataSource 仍然为此 indexSet 提供单元格。
  • @gWiz:当单元格被删除时,单元格不会被自动删除吗?
  • 仅在用户界面中。但是,如果您的 -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 仍然为已删除的 indexSet 提供它们,那可能是个问题。例如,我知道,如果您删除 tableView 中的最后一个单元格,但您的 cellForRowAtIndexPath... 仍然提供单元格(因为例如,您提供它们的数组内部仍然有项目),则应用程序崩溃。

标签: ios objective-c ios7 uicollectionview


【解决方案1】:

在viewDidDisappear 上将您的表视图委托设置为nil

【讨论】:

  • 你的意思是集合视图委托?我的视图并没有消失,我只是删除了集合视图中的一个部分(=行)。
  • 当我在viewDidDisappear 中将代理设置为nil 时,当视图消失、重新出现并且我删除该部分时,应用程序不再崩溃。这已经是一种改进。但是,当视图重新出现时,集合视图有时是空的(即使调用了 numberOfSection 和 numberOfRowsInSection 方法并返回正确的值)。关于为什么收藏有时仍然是空的有什么想法吗?顺便说一句:您的意思是将delegate 或datasource 设置为nil?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-13
  • 1970-01-01
  • 2019-06-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多