【问题标题】:Error "No known class method for selector 'Hello:'" in custom-made framework自定义框架中的错误“选择器'Hello:'没有已知的类方法”
【发布时间】:2011-09-15 17:51:38
【问题描述】:

我正在为一家公司制作一个框架,并且我已经完成了所有代码。我现在正在尝试将其打包到一个框架中。作为测试,我用这个名字做了一个方法:-(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

【问题讨论】:

    标签: objective-c ios cocoa-touch compiler-errors ios-frameworks


    【解决方案1】:

    您将Hello: 定义为实例方法,但您将Hello: 发送到类。要定义一个类方法,请编写 + (void)Hello: 而不是 - (void)Hello:

    【讨论】:

      【解决方案2】:

      请参考: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"];

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-21
        • 2014-09-16
        • 1970-01-01
        相关资源
        最近更新 更多