错误“在定制的框架中没有select器”Hello:“的已知类方法

我正在为一家公司制作一个框架,而且我已经完成了所有的代码。 我现在试图把它打包到一个框架中。 作为一个testing,我用这个名字做了一个方法: -(void)Hello:(NSString *)worldText;

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

没有已知的select器类的方法“Hello:”

在我的框架中的.m如下所示:

 #import "Hello.h" @implementation Hello - (id)init { self = [super init]; if (self) { // Initialization code here. } return self; } -(void)Hello:(NSString *)world { } @end 

在我的框架中的.h如下所示:

 #import <Foundation/Foundation.h> @interface Hello : NSObject -(void)Hello:(NSString *)world; @end 

在我的应用程序中

 // // 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 

在我的应用程序中

 // // 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. // eg 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 

你定义了Hello:作为一个实例方法,但是你发送Hello:给类。 要定义一个类方法,你要写+ (void)Hello:而不是- (void)Hello:

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

回答你的问题,改变

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

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

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