【问题标题】:Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <CALayerArray: 0x66522e0> was mutated while being enumerated由于未捕获的异常“NSGenericException”而终止应用程序,原因:“*** Collection <CALayerArray: 0x66522e0> 在枚举时发生了突变
【发布时间】:2012-11-27 04:38:58
【问题描述】:

有时我的应用程序会因为显示 * Collection was mutated while being enumerated 而崩溃。这一直发生在同一行代码中。请帮助我解决这个问题。我坚持这一点。该应用程序在推送我的代码的视图控制器行时崩溃。但这并不常见。我的错误控制台

由于未捕获的异常“NSGenericException”而终止应用程序,原因:“* Collection CALayerArray: 0x1030c730 在枚举时发生了突变。 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", “” )'

我的代码:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
 ServiceDetails *service=[[ServiceDetails  alloc] initWithNibName:@"ServiceDetails"   bundle:nil];  
    CompanyListingForm *list=[[CompanyListingForm  alloc]initWithNibName:@"CompanyListingForm" bundle:nil];
[category_company_text resignFirstResponder];
if(viewHoldingTable)
{
    [viewHoldingTable removeFromSuperview];
}
if (category_clicked_flag==0) {
    if (location_or_cat_com==0) {
        NSMutableArray *get=[district_array objectAtIndex:indexPath.row];
        locationid=[[get objectAtIndex:0]intValue];
        [location_textfield resignFirstResponder];
        location_textfield.text=[get objectAtIndex:1];
    }
    else
    {
        if (draggingView) {
            [draggingView removeFromSuperview];

        }
        if (viewHoldingTable) {
            [viewHoldingTable removeFromSuperview];
        }


        NSMutableArray *get=[company_array objectAtIndex:indexPath.row];
        category_company_text.text=[get objectAtIndex:1];



        service.ida=[NSString stringWithFormat:@"%d",[[get objectAtIndex:0] intValue]];

        service.idloc=[NSString stringWithFormat:@"%d",locationid];



        [self.navigationController pushViewController:service animated:YES];//getting error at this point.

        //[emer release];   
    }
}
else
{
    if (location_or_cat_com==0) {
        NSMutableArray *get=[district_array objectAtIndex:indexPath.row];
        locationid=[[get objectAtIndex:0]intValue];
        [location_textfield resignFirstResponder];
        location_textfield.text=[get objectAtIndex:1];
    }
    else
    {
        NSMutableArray *get=[category_array objectAtIndex:indexPath.row];
        category_company_text.text=[get objectAtIndex:1];
        int catid=[[get objectAtIndex:0]intValue];

        list.IDForLoc=[NSString stringWithFormat:@"%d",locationid];
        list.IDForCat=[NSString stringWithFormat:@"%d",catid];
        list.companydetails=[get objectAtIndex:1];
        [self.navigationController pushViewController:list animated:YES];//getting error at this point.

    } 
}
 [service release];
 [list release];
}

【问题讨论】:

  • NSMutableArray *getArr = [NSMutableArray arrayWithArray:[[district_array objectAtIndex:indexPath.row]];试试这个。
  • 谢谢你的重播。我试过了,但它仍然存在。在同一行。你看到我的代码行导致这个错误了吗?我在将视图推送到导航控制器时出错。
  • 是 District_array NSMutableArray 的 NSMutableArray 的吗?
  • ya.you 是对的,它是 NSMutableArray 的 NSMutableArray

标签: iphone ios ios4


【解决方案1】:

我认为问题在于您在要求推送视图控制器的同时对界面执行所有这些操作。尝试将pushViewController 行包装在dispatch_after 块中,延迟例如0.1 秒,以使接口的其他更改有时间稳定下来。或者换一种方式:将removeFromSuperview 的东西延迟。更好的是,抛出某种标志,以便稍后在viewWillAppear 上删除要从超级视图中删除的内容。你现在不需要这样做;无论如何,您将要隐藏以使用推送的视图控制器覆盖此视图。

【讨论】:

  • 我试过了。它还在。 viewHoldingTable.hidden=YES; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.6* NSEC_PER_SEC), dispatch_get_current_queue(), ^{ [self.navigationController pushViewController:company_free animated:YES]; });
  • 还有一件事,这不是一个常见的错误,它发生在两次或多次导航推送之后。我的 company_free 包含一些我的视图的阴影设置代码
  • 感谢您的解决方案。我尝试了一些修改。它工作正常。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多