可能是一個noob問題,但它在這裏。我有我的AppDelegate從「application 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的方法。
謝謝大家。
謝謝!我忘記了類方法和實例方法。感謝您寫出我需要的方法。 –