web-dev-qa-db-ja.com

カスタムメイドフレームワークのエラー「セレクタ 'Hello:'の既知のクラスメソッドはありません」

私は会社のフレームワークを作成しており、すべてのコードを完成させました。私はそれをフレームワークにパッケージ化しようとしています。テストとして、次の名前のメソッドを作成しました:-(void)Hello:(NSString *)worldText;

このコードを使用してフレームワークでアプリケーションでそれを呼び出そうとすると[CompanyMobile Hello:@"World"];、次のようなコンパイラエラーが発生します

セレクタ '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

アプリケーションの.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

アプリケーションの.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
12
Sam Baumgarten

_Hello:_をインスタンスメソッドとして定義しましたが、_Hello:_をクラスに送信しています。クラスメソッドを定義するには、+ (void)Hello:ではなく- (void)Hello:を記述します。

48
Chuck

参照してください: 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"];を呼び出します

11
Tatvamasi