replaceObjectAtIndex:withObject:传入NSString对象时不起作用



我试图替换NSMutableArray中特定索引处的对象,但我收到了如下所示的错误

2012-07-30 14:50:11.380 PK[3588:907] -[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x1eded800
2012-07-30 14:50:11.383 PK[3588:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x1eded800'
*** First throw call stack:
(0x357ae56b 0x35a8e97f 0x357b24fb 0x357b0c0d 0x35702e68 0x1082df 0x368528dd 0x3690c869 0x368528dd 0x3685288f 0x3685286d 0x368525c3 0x36852f41 0x36851359 0x3683f2e1 0x3683eb5b 0x385c05f3 0x385c0223 0x3577ec33 0x3577ebd7 0x3577d9d1 0x356fbc1d 0x356fbaa9 0x385bf33b 0x36865535 0x104175 0x344c6b20)
libc++abi.dylib: terminate called throwing an exception

我已经在标头中将数组声明为NSMutableArray,因此任何想要使用它的方法都可以广泛使用它,下面展示了我在尝试设置NSDictionary对象时如何使用它。

//...
// Objects for keys that are for sendSeriesDictionary
    seriesObjects = [NSArray arrayWithObjects: [NSNull null], [NSNull null], [NSNull null], nil];

    if ([manufactureIdString length] != 0) {
        [seriesObjects replaceObjectAtIndex:0 withObject:IdString];
    }
    if ([modelIdString length] != 0) {
        [seriesObjects replaceObjectAtIndex:1 withObject:mIdString];
    }
    if ([subModelIdString length] != 0) {
       [seriesObjects replaceObjectAtIndex:2 withObject:sIdString];
    }
//..

一旦线程进入第一个if语句,就是当我得到上面列出的错误时。。我最初将NSMutableArray设置为[NSNull-null]的原因是,如果3个字符串中的任何一个为空,那么当这些数据作为对与我通信的服务器的调用传递时,数组中的对象将不会进一步出错。

任何帮助都将不胜感激。。。我觉得我所做的应该是有效的,但我也认为错误可能是由我在数组对象中传入[NSNull-null]引起的。。但这只是我的观察,也许你们可以告诉我更多的情况。

创建一个类似的可变数组

seriesObjects = [NSMutableArray arrayWithObjects: [NSNull null], [NSNull null], [NSNull null], nil];

并声明seriesObjects

NSMutableArray *seriesObjects;

删除警告

最新更新