In secondViewController, create a protocol such as:
@protocol SecondViewScreenControllerDelegate <NSObject> - (void)secondViewScreenControllerDidPressCancelButton:(UIViewController *)viewController sender:(id)sender;
Now you need to add the property to the secondViewController class:
@property (weak, nonatomic) id<SecondViewScreenControllerDelegate> delegate;
You insert it into the secondViewController implementation:
@synthesize delegate = _delegate;
Finally, all you have to do is implement the protocol in your first controller and configure the second control monitor correctly before presenting it:
@interface firstViewController : UIViewController <SecondViewScreenControllerDelegate>
...
@implementation firstViewController - (void)secondViewScreenControllerDidPressCancelButton:(UIViewController *)viewController sender:(id)sender {
Then, when presenting the second, the ViewController from the first:
UIViewController *sec = [[SecondViewController alloc] init];
And ready. Whenever you want to cancel the second control controller the first time, just call: (inside the implementation of the second ViewController)
[self.delegate secondViewScreenControllerDidPressCancelButton:self sender:nil]; // Use nil or any other object to send as a sender
All that happens is that you send a pointer to the second control, which you can use from the first. Then you can work with it without any problems. No C ++ required. In Cocoa, you won't need C ++. Almost everything can be done using Objective-C, and it is more dynamic.