ios 自定义框架中的错误“没有已知的选择器'Hello:'的类方法”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6361704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:22:46  来源:igfitidea点击:

Error "No known class method for selector 'Hello:'" in custom-made framework

objective-cioscocoa-touchcompiler-errorsios-frameworks

提问by Sam Baumgarten

I am making a framework for a company and I have completed all the code. I'm now trying to package it into a framework. As a test I made a method with this name: -(void)Hello:(NSString *)worldText;

我正在为一家公司制作一个框架,我已经完成了所有的代码。我现在正试图将它打包成一个框架。作为测试,我创建了一个具有此名称的方法:-(void)Hello:(NSString *)worldText;

When I try to call it in the application with the framework using this code [CompanyMobile Hello:@"World"];, I'm getting a compiler error which says

当我尝试使用此代码在带有框架的应用程序中调用它时[CompanyMobile Hello:@"World"];,我收到一个编译器错误,它说

No known class method for selector 'Hello:'

选择器 'Hello:' 没有已知的类方法

The .m in my framework is as follows:

我框架中的 .m 如下:

#import "Hello.h"

@implementation Hello

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }

    return self;
}

-(void)Hello:(NSString *)world {

}

@end

The .h in my framework is as follows:

我框架中的 .h 如下:

#import <Foundation/Foundation.h>

@interface Hello : NSObject
-(void)Hello:(NSString *)world;
@end

The .h in my application

我的应用程序中的 .h

//
//  FMWK_TESTViewController.h
//  FMWK TEST
//
//  Created by Sam on 6/15/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <companyMobile/Hello.h>
@interface FMWK_TESTViewController : UIViewController

@end

The .m in my application

我的应用程序中的 .m

//
//  FMWK_TESTViewController.m
//  FMWK TEST
//
//  Created by Sam Baumgarten on 6/15/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "FMWK_TESTViewController.h"

@implementation FMWK_TESTViewController

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [Badgeville Hello:@"Sam"];
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}

@end

回答by Chuck

You defined Hello:as an instance method, but you're sending Hello:to the class. To define a class method, you write + (void)Hello:rather than - (void)Hello:.

您定义Hello:为实例方法,但您正在发送Hello:给类。要定义类方法,请编写+ (void)Hello:而不是- (void)Hello:.

回答by Tatvamasi

please refer to : https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html

请参考:https: //developer.apple.com/library/content/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html

to answer your question, change

回答你的问题,改变

@interface Hello : NSObject
-(void)Hello:(NSString *)world;
@end 

to

@interface CompanyMobile : NSObject{
}
+(void)Hello:(NSString *)world;
@end

and call the method [CompanyMobile Hello:@"world"];

并调用该方法 [CompanyMobile Hello:@"world"];