我对 iOS 编程很陌生。我正在尝试使用下面列出的方法来遍历我的存档对象(nsuserdefaults)并显示它的内容。当我尝试使用下面的代码时出现错误,应用程序崩溃:
-[NSUserDefaults objectEnumerator]: unrecognized selector sent
如果有人可以帮助我,那就太好了,我相信我循环不正确......
-(IBAction)loadNames:(id)sender {
NSString *fileName = [[NSString alloc] initWithFormat:@"%@", usertext.text];
NSFileManager *manager = [NSFileManager defaultManager];
User * userr = [User alloc];
userr = [NSKeyedUnarchiver unarchiveObjectWithFile:fileName];
NSUserDefaults * lg = [NSUserDefaults standardUserDefaults];
NSData *encodedUser = [NSKeyedArchiver archivedDataWithRootObject:userr];
[lg setObject:encodedUser forKey:@"userr"];
NSEnumerator *e = [lg objectEnumerator];
while (lg = [e nextObject]) {
NSLog(@"%@", usertext);
}
}