我的代码给出了一个错误提示
。H
@interface ViewController : UIViewController{
NSMutableDictionary *credtialsDictionary;
}
-(IBAction)registerlogin;
@end
.m
@implementation ViewController
-(IBAction)registerlogin{
[credtialsDictionary addObjects:passwordFieldregister.text forKey:usernameFieldregister];
}
@end
我不知道为什么这个
IBAction
不让我向NSMutableDictionary
添加对象 最佳答案
因为addObjects:forKey:
中没有实例方法NSMutableDictionary
。
您正在寻找的方法是setObject:forKey:
。 (https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/Reference/Reference.html)
如果您说出为什么认为该方法应为addObjects:forKey:
,我可以以更通用的方式为您提供帮助。但是总的来说,您想查看Apple的文档(如上面的链接,通常只是google类名),或者查看标题,在Xcode中,您可以按Cmd-Shit-O然后输入类的名称您可以从此处打开标题。
在这种情况下,您使用错误方法的线索是addObjects
是复数形式(而forKey
不是复数形式),而您只是试图添加一个对象。