Pregunta

Estoy haciendo un marco para una empresa y he completado todo el código. Ahora estoy tratando de empaquetarlo en un marco. Como prueba, hice un método con este nombre: -(void)Hello:(NSString *)worldText;

Cuando intento llamarlo en la aplicación con el marco usando este código [CompanyMobile Hello:@"World"];, Recibo un error del compilador que dice

No hay método de clase conocido para el selector 'Hola:'

El .m en mi marco es el siguiente:

#import "Hello.h"

@implementation Hello

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

    return self;
}

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

}

@end

El .h en mi marco es el siguiente:

#import <Foundation/Foundation.h>

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

El .h en mi aplicación

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

El .m en mi aplicación

//
//  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
¿Fue útil?

Solución

Definiste Hello: Como método de instancia, pero estás enviando Hello: a la clase. Para definir un método de clase, usted escribe + (void)Hello: más bien que - (void)Hello:.

Otros consejos

por favor refiérase a : https://developer.apple.com/library/content/documentation/cocoa/conceptual/programmingwithobjectivec/introduction/introduction.html

Para responder a su pregunta, cambie

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

a

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

y llamar al método [CompanyMobile Hello:@"world"];

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top