How To Call A Method Of A Class From Another Class?

In my last post, I told you to check out this post. :) Here's my last message:

"In my case, the app has one main screen. But this screen is composed of 2 different classes: the MAP and the CONFIG classes. I had a problem in changing the views properties of the CONFIG class from the MAP class. If you are having the same problem, click the link above (the one with blue lines :) )."

Talking again about my problem, when I try to access the CONFIG's views properties, the properties stay the same, meaning they are not changing. The problem was I was making a new instance of the CONFIG Class from my MAP Class. I was so dumb, well until now I am. :) Thanks to our kind CTO for pointing this out. I have been applying this learning up to this date.

1. Import Class Header to the class to which you will call the method from class 2.
2. make an instance of the class 2 and make it a property
@property (nonatomic, strong) Class2 *class2Instance;

3. Then instantiate your instance.
self.class2Instance = [Class2 new];

4. Call now the method of the class2 from class1 using the property instance. But don't forget to declare your method in class1 header as property
[_class2Instance someMethods];



That's all! If you find this post helpful, please subscribe!

Post a Comment