I have two view controllers. MainViewController pushes SignUp ViewController. Once SignUp View Controller dismisses, I need access to the same instance of MainViewController to update a UIButton.title.
.h MainView
//MainViewController.h
#import <UIKit/UIKit.h>
@interface MainViewController : UITableViewController
-(void)loggedIn;
@end
.m
@interface MainViewController ()
@end
-(void)loggedIn
{
NSLog (@"This is Logged in inside MainView.m");
self.logInOutButton.title = @"Logout";
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UIViewController *destinationViewController = segue.destinationViewController;
Signup *signUp = [destinationViewController isKindOfClass:[SignUp class]] ? (Signup*)destinationViewController : nil;
signUp.mainViewController = self;
NSLog(@"Preapre For Segue %@", self);
}
.h SignUp
#import <UIKit/UIKit.h>
#import "MainViewController.h"
@interface SignUp : UIViewController
@property (strong, nonatomic) MainViewController *mainViewController;
@end
.m
@synthesize mainViewController;
- (void) loggedIn
{
NSLog(@" MainViewController %@", mainViewController);
[mainViewController loggedIn];
self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
When I do NSLog I'm getting different values:
Preapre For Seg <STMainViewController: 0x9f7d600>
MainViewController (null)