Claudia Mardegan
Claudia Mardegan

Reputation: 567

How to call a method in another class?

I would like to have only one class for control my menu. I try used this:

In the .h

 #define Generic ((AppDelegate*)[[UIApplication sharedApplication] delegate])
 #import <UIKit/UIKit.h>

 @interface Generic : UIViewController

 - (IBAction)photo:(id)sender;

 @property (nonatomic, strong) NSString *apareceMenu;

 @end

in the .m

- (IBAction)photo:(id)sender{
    NSLog(@"Ok");

}

Now i need read the - (IBAction)photo in other class, But i don't know how.

I believe to be something

[Generic photo];

Could someone help me please?

Upvotes: 0

Views: 1658

Answers (3)

Mahe
Mahe

Reputation: 98

create object for Generic class and call photo via that object [genericObj photo];

Upvotes: 0

user2625110
user2625110

Reputation:

[Generic photo:] is correct method to call the function. Before the you must do this steps in another class.

Generic *genericObj = [[Generic alloc]initWithNibName:@"Generic" bundle:nil];

then you call your class like,

[genericObj photo];

Upvotes: 1

Lyndsey Scott
Lyndsey Scott

Reputation: 37290

Follow the instructions in this post:

How to call method from one class in another (iOS) https://stackoverflow.com/a/9731162/2274694

Upvotes: 2

Related Questions