Probably a noob problem but here it is. I have my AppDelegate instantiating a new dictionary from a file in “application didFinishLaunchingWithOptions”. I have an addViewController that I would like to pass a new object to be added to the AppDelegate’s dictionary, for later saving to disk. Here’s some snippets of what I’ve got.
//
// 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"];
and the 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
}
I know this is probably basic but I’m really confused. I’m importing the AppDelegate.h file in the addViewController, so it should know all about AppDelegate’s methods.
Thanks everyone.
The line:
is attempting to call a class method named
addtoDict:on the the class namedAppDelegate. Most likely you want to call theaddtoDict:instance method (not class method) on your app’s app delegate instance.You probably want: