Objective c &引用;选择器“的类方法未知”;混乱
可能是个问题,但问题就在这里。我让我的AppDelegate从“application didFinishLaunchingWithOptions”中的文件实例化一个新词典。我有一个addViewController,我想传递一个新对象以添加到AppDelegate的字典中,以便以后保存到磁盘。这是我得到的一些片段Objective c &引用;选择器“的类方法未知”;混乱,objective-c,cocoa-touch,cocoa,Objective C,Cocoa Touch,Cocoa,可能是个问题,但问题就在这里。我让我的AppDelegate从“application didFinishLaunchingWithOptions”中的文件实例化一个新词典。我有一个addViewController,我想传递一个新对象以添加到AppDelegate的字典中,以便以后保存到磁盘。这是我得到的一些片段 // // AppDelegate.m // PersonLibraryiOS // // Created by Joey on 11/7/12. // Copyright
//
// 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.m
//个人图书馆
//
//由乔伊于2012年11月8日创作。
//版权所有(c)2012乔伊。版权所有。
//
#导入“AddViewController.h”
#导入“TableViewController.h”
#输入“person.h”
#导入“AppDelegate.h”
@AddViewController的实现
@综合姓名标签;
@综合年龄标签;
@合成高度标签;
@合成权重标签;
@合成发色标签;
@合成色素标签;
-(iAction)保存按钮:(id)发送者
{
person*newperson=[[person alloc]init];
newperson.name=[nameLabel文本];
newperson.age=[ageLabel text];
newperson.height=[heightLabel text];
newperson.weight=[weightLabel文本];
newperson.hairolor=[hairolorlabel text];
newperson.eyeColor=[eyeColorLabel text];
[AppDelegate addtoDict:newperson];AppDelegate是一个类。您可能想与充当应用程序委托的类的特定实例对话,该实例将是[[UIApplication sharedApplication]委托]
。类与其实例不可互换。行:
[AppDelegate addtoDict:newperson];
正在尝试调用名为AppDelegate
的类上名为addtoDict:
的类方法。很可能您希望调用应用程序的app delegate实例上名为addtoDict:
的实例方法(非类方法)
您可能想要:
[(AppDelegate *)[NSApplication sharedApplication].delegate addtoDict:newperson];
谢谢!我忘了类方法和实例方法。谢谢你写出我需要的方法。非常感谢你,先生。~bows~