简体   繁体   中英

Objective-C: Instance method 'method' is being used on 'Class' which is not in the root class

I am getting warning: Instance method 'method' is being used on 'Class' which is not in the root class.

I am calling this method (which is defined in the super class) in the static method. When I execute the code, I get runtime error: unrecognized selector sent to class .

Is it possible to solve this problem? Is it possible to call super class method inside the static method?

Thank you

EDIT :

Child class:

@interface ProfileClass : GHAsyncTestCase {}
+ (void)testGHUnitSuccess;
@end

@implementation ProfileClass
+ (void)testGHUnitSuccess {
    [self waitForStatus:kGHUnitWaitStatusSuccess timeout:10.0];
}
@end

GHAsyncTestCase is class from GHUnit framework. Maybe, it is not possible to call the super class method in static method. If not, I will have to solve it in different way.

SOLUTION :

I have created shared instance of my super class and have used it in the static methods.

Simple answer is no.

To call an instance method you must have an instance of the class to send the message to. In a static method you do not have an instance of the class.

Thus you either need to convert the called method to a static method - which should be possible if the method does not depend on any values of the instance or you have to create an instance of the class (alloc, init etc) in the static method.

We cannot provide a more concrete way out without seeing your code.

EDIT: After your edit it can bee seen what the issue is.
In a class method (+ (void)testGHUnitSuccess - note not a static method) self is the class which does not have the instance methods. Thus as you say you need to replace self by an instance of the class - in this case a shared instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM