从NSMutableArray中删除对象时崩溃 [英] crash while removing objects from NSMutableArray

查看:578
本文介绍了从NSMutableArray中删除对象时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的iphone项目中(启用了ARC)我有一个 nsmuatble 数组,其中包含5个托管对象(从核心数据中检索),在某些情况下我需要从 nsmutablearray中删除所有对象

In my iphone project (ARC enabled) i have a nsmuatble array which contains some 5 managed objects (which are retrieved from core data ) and in some scenario i need to remove all the objects from that nsmutablearray

我使用了以下方法删除对象,但在两种情况下都崩溃了崩溃日志 - [__ NSArrayI removeObject:]:无法识别的选择器发送到实例0xa391640

i have used following methods to remove objects but its crashing in both the cases with the crash log -[__NSArrayI removeObject:]: unrecognized selector sent to instance 0xa391640

if (surveys && [surveys count]>0)
        {

            [surveys removeAllObjects];
            surveys = [[NSMutableArray alloc]init];
        }

我还试过

if (surveys && [surveys count]>0)
        {
            for(Survey *obj_Survey in surveys)
            {
                [surveys removeObject:obj_Survey];
            }

            surveys = [[NSMutableArray alloc]init];
        }

任何人都可以告诉我如何清空该阵列,任何建议都会赞赏,thanx提前

can any one tell me how do i empty that array,, any suggestions would be appreciated, thanx in advance

推荐答案

答案非常简单。

对于第一种情况。

检查初始化数组的部分,如果已经为NSMutableArray对象分配了NSArray,请检查代码中的某处。

For First case.
Check the part where you have initialized your array, and check if somewhere through your code, if you have assigned an NSArray to your NSMutableArray object.

对于第二种情况。

当您通过它枚举时,无法从数组中删除对象。这将导致崩溃,说数组在枚举时发生了变异

这篇关于从NSMutableArray中删除对象时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆