Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
657 views
in Technique[技术] by (71.8m points)

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

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;

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

No known class method for selector 'Hello:'

The .m in my framework is as follows:

#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:

#import <Foundation/Foundation.h>

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

The .h in my application

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

//
//  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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...