replaceObjectAtIndex:i withObject:str给出了错误的访问错误(也有删除对象 - 甚至我可以addObject atIndex

时间:2011-02-16 23:33:38

标签: nsmutablearray exc-bad-access

我正在尝试使用在数组索引处找到的字符串(其他数组)替换数组(更新数组)中的字符串。两个数组都在init中初始化,我可以在这个方法中对它们进行nslog。 if [str isEqualToString:[otherArray objectAtIndex:i]我想返回true / YES

但行:[updateArray replaceObjectAtIndex:i withObject:str];对程序的访问权限很差。 (它只是一个控制台程序)“程序接收信号:”EXC_BAD_ACCESS“。

任何赞赏的建议,谢谢trev

-(BOOL)checker:(NSString *)str {

    NSLog(@"update arrayobject at %d is %@",0, [updateArray objectAtIndex:0]);  


    NSLog(@"otherArray size is %d",[otherArray count]);
    NSLog(@"str iput is %@",str);
    int i;
    for (i=0; i<[otherArray count]; i++) {
        if ([str isEqualToString:[otherArray objectAtIndex:i]]) {
            [updateArray replaceObjectAtIndex:i withObject:str];
        return TRUE;
        }

    }   
        return FALSE;
}

1 个答案:

答案 0 :(得分:0)

一旦检查你的阵列是否分配或不正确..我认为只有那个东西..