2012-01-30 129 views
-1

我:为什么这个代码有错误?

boardValue = [NSNumber numberWithInteger: 2]; 
NSDictionary * dict = [NSDictionary dictionaryWithValuesForKeys: @"sample", @"word", boardValue , @"value", nil]; 

这非常类似于下面的例子:

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: @"value1", @"key1", @"value2", @"key2", nil]; 

从苹果单证在: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsdictionary_Class/Reference/Reference.html

我得到的错误“太多的参数的方法调用,期望1,有5“。问题是什么?

回答

2

dictionaryWithValuesForKeys:an array作为参数,而不是变量的参数列表。

(另外,我认为它是一个实例方法,而不是一个类的方法,所以[NSDictionary的dictionaryWithValuesForKeys:参数]`将无法工作。)

1

通知你的代码相比文档。您想致电...

boardValue = [NSNumber numberWithInteger: 2]; 
NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys: @"sample", @"word", boardValue , @"value", nil];