0

Objective-C には少し慣れていないので、ご容赦ください。

まず、SQLite の管理に FMDB ライブラリを使用しています。

次のメソッドを使用して 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]];

}

次の 2 つのメソッドを呼び出します。

-(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 の入力ではなく、取得時に発生します。これは、このディクショナリの人口が問題ではないことを意味しますが、データの取得に問題がある理由と関係がある可能性があります。

では、このエラーの原因は何でしょうか?

4

1 に答える 1

2

あなたのコードは従うのがかなり難しいです。将来的には、コンパイルできる、または少なくとも理解可能なコードの単一ブロックである最小限のサンプルを投稿してください。

そうは言っても、あなたの問題はこのビットにあると思います:

for(id type in tEffect) //tEffect is the NSMutableDictionary, returned from the previous code (there known as resultDict)
{
    effectivenessString = [self getEffectivenessString:[tEffect objectForKey:type]];

何がresultDict含まれていますか?

[resultDict setObject:dFactors ...

しかしdFactorsNSMutableArrayです。ではなく、 がgetEffectivenessString期待されます。だから文句を言う。また、メソッドが数値ではなく文字列を取ることを意図していたと思いますが、ロードするときに(使用するのではなく)キャストしない理由はわかりません。NSNumberNSMutableArray

Objective C は厳密に型指定された配列やディクショナリをサポートしていないため、将来これを防ぐための最善の策は、変数にもっと論理的な名前を付けることです。代わりに配列を持つ数値を期待するメソッドを呼び出そうとすると、目立つはずです。

于 2013-08-04T18:31:16.400 に答える