Objective-C 有点新,所以请多多包涵。
首先,我使用 FMDB 库进行 SQLite 管理。
我正在使用以下方法填充 NSMutableDictionary:
//....
while([effectivenessResults next]) //this loops through the results of a query (verified that this works)
{
NSMutableArray *dFactors = [[NSMutableArray alloc]init];
if([resultDict objectForKey:[effectivenessResults stringForColumn:@"tName"]])
{
dFactors = [resultDict objectForKey:[effectivenessResults stringForColumn:@"tName"]];
}
NSNumber *effectivenessValToAdd = [NSNumber numberWithDouble:[effectivenessResults doubleForColumn:@"dFactor"]/100];
[dFactors addObject:[NSMutableString stringWithFormat:@"%@",effectivenessValToAdd]];
[resultDict setObject:dFactors forKey:[effectivenessResults stringForColumn:@"tName"]];
}
我正在正确返回数组(我已经验证了这一点)。然后,我在其他地方访问这个 NSMutableDictionary,使用以下方法:
for(id type in tEffect) //tEffect is the NSMutableDictionary, returned from the previous code (there known as resultDict)
{
effectivenessString = [self getEffectivenessString:[tEffect objectForKey:type]];
tInfo = [NSMutableString stringWithFormat:@"%@", [tInfo stringByAppendingFormat:@"%@: %@\n", type, effectivenessString]];
}
它调用以下两种方法:
-(NSMutableString *)getEffectivenessString:(NSNumber *) numberPassedIn
{
double dFactor = [numberPassedIn doubleValue];
//adds the above value to a string, this will not affect anything
}
和
-(NSNumber *) listProduct: (NSMutableArray *)listOfValues //calculates the product of an NSMutableArray of numbers
{
NSNumber *product=[NSNumber numberWithDouble:1.0];
for(int i = 0; i < [listOfValues count]; i++)
{
NSNumber *newVal = [listOfValues objectAtIndex:i];
product = [NSNumber numberWithDouble:[product doubleValue] * [newVal doubleValue]];
}
return product;
}
所以,当我调用这些方法时,我收到以下错误:
2013-08-04 13:52:04.514 effectCalculator[45573:c07] -[__NSArrayM doubleValue]:
unrecognized selector sent to instance 0x8c19e00
2013-08-04 13:52:04.521 effectCalculator[45573:c07] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '-[__NSArrayM doubleValue]: unrecognized
selector sent to instance 0x8c19e00'
需要注意的重要事项:此错误发生在检索时,而不是 NSMutableDictionary 的填充。这意味着这本字典的数量不是问题,但它可能与它在检索数据时遇到问题的原因有关。
那么什么可能导致这个错误呢?