【问题标题】:Objective C - No know class method for selection目标 C - 不知道用于选择的类方法
【发布时间】:2018-10-08 08:37:14
【问题描述】:

我正在尝试实现一个数据库系统,其中一个实体在其 DataClass.m 中包含一些方法,但我无法在我的 ViewController.m 中调用它们

在上面的代码中,我尝试调用 savePersona 但构建显示

选择器没有已知的类方法 'savePersona:etaLabel:indirizzoLabel:contextLabel:'

ViewController.m

#import "ViewController.h"
#import "Giovanni+CoreDataClass.h"
#import "AppDelegate.h"


@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

/*
 * Event after clicking button Save.
 */
- (IBAction)btnSave:(id)sender {
    NSString *nome = _insertName.text;
    NSString *eta = _insertAge.text;
    NSString *indirizzo = _insertIndirizzo.text;

    // Check for all inputs
    if ([nome isEqualToString:@""] || [eta isEqualToString:@""] || [eta intValue] <= 0 || [indirizzo isEqualToString:@""] ) {
        _resultText.text = @"All fields are required";
        return;
    }


    [Giovanni savePersona:nome etaLabel:[eta intValue] indirizzoLabel:indirizzo contextLabel:[((AppDelegate *)[[UIApplication sharedApplication] delegate]) managedObjectContext]];
}

Giovanni+CoreDataClass.h

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@interface Giovanni : NSManagedObject

+(void)savePersona: (NSString*)nome etaLabel:(int16_t)eta indirizzoLabel:(NSString*)indirizzo contextLabel:(NSManagedObjectContext *)context;

@end

#import "Giovanni+CoreDataProperties.h"

Giovanni+CoreDataClass.m

#import "Giovanni+CoreDataClass.h"

@implementation Giovanni

+(void)savePersona: (NSString*)nome etaLabel:(int16_t)eta indirizzoLabel:(NSString*)indirizzo contextLabel:(NSManagedObjectContext *)context {
    Giovanni *p1 = [[Giovanni alloc] initWithContext:context];
    p1.nome = nome;
    p1.eta = eta;
    p1.indirizzo = indirizzo;
}

在构建阶段,我有 Giovanni+CoreDataClass.m 和 Giovanni+CoreDataProperties.m。 在 Copy Bundle Recources 我有 DatabaseExample.xcdatamodeld (DatabaseExample 是项目的名称)

【问题讨论】:

标签: ios objective-c xcode10


【解决方案1】:

看起来您已将类文件命名为category,但您没有使用categories

尝试将Giovanni+CoreDataClass 重命名为GiovanniCoreData

【讨论】:

  • 当我在 DatabaseExample.xcdatamodeld 中创建实体时,Xcode 自动生成了这个名称。创建一个错误的类名有这么愚蠢吗?
【解决方案2】:

我已经通过重新创建项目解决了我的问题。

什么都没有改变,但是当我点击编辑器 -> 创建 NSManagedObject 子类时,XCode 在自动创建我的实体时遇到了一些问题...

不知道是不是最新版本的bug,现在项目运行正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    • 2020-01-26
    • 1970-01-01
    • 2013-04-04
    • 2014-04-18
    • 2012-07-07
    • 1970-01-01
    相关资源
    最近更新 更多