Tejas Patel
Tejas Patel

Reputation: 870

Call IBAction of another view controller from one viewController

I want to implement one thing in my project in which i want to call SecondViewController IBAction using FirstViewControllers IBAction.

Here is the code that i implement but this is not working.

FirstViewController

- (IBAction)StartRecording:(id)sender
{
SecondViewController *secondVC = [[SecondViewController alloc]init];
[secondVC performSelector:@selector(startStopRecording:)];
}

SecondViewController

-(IBAction)startStopRecording:(UIButton *)sender
{
// Something to do perform
}

Upvotes: 1

Views: 1252

Answers (2)

Abhinav
Abhinav

Reputation: 38142

First of all, please rename your method to right naming convention. It should start with small letter which is the common industry practice.

What you are trying to do is pretty simple and straight forward.

First: Put -(IBAction)startStopRecording:(UIButton *)sender in SecondViewController.h

Second: Call it from FirstViewController like this:

- (IBAction)startRecording:(id)sender {
   SecondViewController *secondController = [[SecondViewController alloc] init];
   [secondController startStopRecording:sender];
}

Upvotes: 3

Vatsal Raval
Vatsal Raval

Reputation: 313

You must declare the method in .h file , that you want to access. In you example , you should declare -(IBAction)startStopRecording:(UIButton *)sender in .h file. And you are done

Upvotes: 3

Related Questions