简体   繁体   中英

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
}

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

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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM