user930195
user930195

Reputation: 432

Method is not calling from another class

I have a "class-A" which contains a method

-(void)methodA
{
//Logic
}

I have another "Class-B" which is a method

-(void)methodB
{
//Logic
}

Now i am trying to call methodA from Class B

So what i do

In Class B

Create an object of "Class-A"

ClassA *a;

@property(nonatomic,retain)ClassA *a;

@synthesize a;

-(void)methodB
{
[self.a methodA];
}

But the method is not called. So what am i doing wrong or any other approach for doing this ?

Upvotes: 0

Views: 112

Answers (1)

Krrish
Krrish

Reputation: 2256

//In class A
//classA.h

@interface classA : NSObject
  -(void)methodA;
@end

//classA.m
@implementation classA
-(void)methodA
{
    //Logic
}
@end


//In class B
//classB.h

#import classA.h 
@interface classB : NSObject

@property(nonatomic,retain)classA *a;

@end

//classB.m
@implementation classB

@synthesize a;

-(void)methodB
{
    if(!self.a) self.a = [[classA alloc]init];
    [self.a methodA];
    //Logic
}

@end

Upvotes: 1

Related Questions