9

Question: How to call superclass static method ?

I mean directly by using:

[SuperClassName method]

OR

There is any other way existed?

Rajesh
  • 10,028
  • 15
  • 40
  • 63
veerababu
  • 155
  • 1
  • 4
  • 8

4 Answers4

8

If you wants to call drive class methods from base class then, declare class method in your drive class like this: using (+) sign before method name.

+(void)myClassMethod;

Call this method from base class like this:

[YourDriveClassName myClassMethod];

Or you wants to call drive class instance methods from base class, declare instance method in your drive class using (-)sign before method name.

-(void)sayHelloToSomeOne:(NSString *)greeting;

Call this method from base class.

[super sayHelloToSomeOne:@"Hello Worlds!"];
Irfan
  • 4,271
  • 6
  • 28
  • 46
Gajendra Rawat
  • 3,613
  • 2
  • 18
  • 36
3

In Objective-C, there are two type of Methods:

1) Class Method

e.g:

+ (void)aClassMethod;

You can call this method by his class name like : [MyClass aClassMethod]

2) Instance Method

e.g:

- (void)anInstanceMethod;

You can call this method by his class's instance name like :

MyClass *object = [[MyClass alloc] init]; [object anInstanceMethod];

Hope this will helps you.

Irfan
  • 4,271
  • 6
  • 28
  • 46
2

If the call is from a static method. That is

+ (void)someMethod{
  [self method];
}

if call is from an instance method it is really required to call it like

- (void)someMethod{
  [SuperClassName method];
}
Rajesh
  • 10,028
  • 15
  • 40
  • 63
1

You will declare a class level method in iOS to use "+" before the method declaration.

declared in your class.h file

+ (void)yourStaticMethod;

// call is from anywhere

[yourClassName myStaticMethod];
codercat
  • 22,159
  • 9
  • 58
  • 84