I try to pass data from one ViewController to secondControler however seem it not work. I use NSNotification. - 2 Controller have same class "ViewController"
In viewcontroller.m
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(ProcessBarLoading) name:@"buttonPressed" object:nil];
}
-(void)ProcessBarLoading{
_labelTest.stringValue = @"TESTING";
}
- (IBAction)test:(id)sender {
[[NSNotificationCenter defaultCenter] postNotificationName:@"buttonPressed" object:self];
NSStoryboard *storyboard = [NSStoryboard storyboardWithName:@"Main" bundle: nil];
NSViewController * vc = [storyboard instantiateControllerWithIdentifier:@"SheetViewController"];
[self presentViewControllerAsSheet:vc];
}
When run program and press button, there're no update Label Text at all. Do you know why and how I can fix.
New Code: In SecondViewController.m
@interface SencondViewController ()
@end
@implementation SencondViewController
@synthesize progressValue;
@synthesize labelView;
- (void)viewDidLoad {
[super viewDidLoad];
// Do view setup here.
labelView.stringValue =progressValue;
}
In FirstViewCOntroller:
- (IBAction)test:(id)sender {
self->uide = @"0";
[self performSegueWithIdentifier:@"showRecipeDetail" sender:self->uide];
NSStoryboard *storyboard = [NSStoryboard storyboardWithName:@"Main" bundle: nil];
NSViewController * vc = [storyboard instantiateControllerWithIdentifier:@"SheetViewController"];
[self presentViewControllerAsSheet:vc];
- (void)prepareForSegue:(NSStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showRecipeDetail"]) {
SencondViewController * secondVC = segue.destinationController;
secondVC.progressValue = uide;
}
}
- (IBAction)test2:(id)sender {
uide = @"80";
[self performSegueWithIdentifier:@"showRecipeDetail" sender:uide];
[self.view displayIfNeeded];
}
So whether I press Button 1(test) other Button2 (test2) alway show new view with update value. What I need is only show 1 view.