gpt4 book ai didi

objective-c - "no known class method for selector"困惑

转载 作者:行者123 更新时间:2023-12-03 17:28:51 31 4
gpt4 key购买 nike

可能是菜鸟问题,但就是这样。我让我的 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 方法的所有信息。

谢谢大家。

最佳答案

AppDelegate 是一个类。您可能想要与充当应用程序委托(delegate)的类的特定实例进行通信,该实例是 [[UIApplication sharedApplication] delegate]。类与其实例不可互换。

关于objective-c - "no known class method for selector"困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13334057/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com