可能是一个菜鸟问题,但在这里。我让我的 AppDelegate 从“应用程序 didFinishLaunchingWithOptions”中的文件实例化一个新字典。我有一个 addViewController,我想传递一个新对象以添加到 AppDelegate 的字典中,以便稍后保存到磁盘。这是我所拥有的一些片段。
//
// AppDelegate.m
// PersonLibraryiOS
//
// Created by Joey on 11/7/12.
// Copyright (c) 2012 Joey. All rights reserved.
//
#import "AppDelegate.h"
#import "AddViewController.h"
#import "Person.h"
@implementation AppDelegate
@synthesize PersonDict;
-(void)addtoDict:(Person *)newPerson
{
[PersonDict setObject:@"newPerson" forKey:[newPerson name]];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
PersonDict = [NSMutableDictionary dictionaryWithContentsOfFile:@"diskDict"];
和 AddViewController:
//
// AddViewController.m
// personLibraryiOS
//
// Created by Joey on 11/8/12.
// Copyright (c) 2012 Joey. All rights reserved.
//
#import "AddViewController.h"
#import "TableViewController.h"
#import "person.h"
#import "AppDelegate.h"
@implementation AddViewController
@synthesize nameLabel;
@synthesize ageLabel;
@synthesize heightLabel;
@synthesize weightLabel;
@synthesize hairColorLabel;
@synthesize eyeColorLabel;
- (IBAction)saveButton:(id)sender
{
person *newperson = [[person alloc]init];
newperson.name = [nameLabel text];
newperson.age = [ageLabel text];
newperson.height = [heightLabel text];
newperson.weight = [weightLabel text];
newperson.hairColor = [hairColorLabel text];
newperson.eyeColor = [eyeColorLabel text];
[AppDelegate addtoDict:newperson]; <---- the error is here
}
我知道这可能是基本的,但我真的很困惑。我在 addViewController 中导入 AppDelegate.h 文件,所以它应该知道所有关于 AppDelegate 的方法。
谢谢大家。