I have two UIViewControllers: TimerViewController and EfficiencyViewController (For simplicity's sake, we will call them TVC and EVC)
I am trying to pass certain values (2 NSString objects, 1 NSTimeInterval)from TVC to EVC when a button is pressed. EVC needs to be intialized and pop up upon pressing the button. Overall, I have tried two methods.
1. Directly passing the values (In TVC)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
EfficiencyViewController *efficiencyViewController = [storyboard instantiateViewControllerWithIdentifier:@"EfficiencyView"];
efficiencyViewController.category = _categoryLabel.text;
efficiencyViewController.desc = _descriptionTextField.text;
efficiencyViewController.duration = [_timer getInterval];
efficiencyViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:efficiencyViewController animated:YES completion:NULL];
Problem: When I instantiate EVC, the values I held in TVC are reset, so basically no data is passed. (I think this is because EVC actually pops up on the screen)
2. Building a custom init method
TVC
EfficiencyViewController *efficiencyViewController = [[EfficiencyViewController alloc] initWithName:_categoryLabel.text desc:_descriptionTextField.text duration:[_timer getInterval]];
[self presentViewController:efficiencyViewController animated:YES completion:NULL];
EVC initWithName method implementation
- (id)initWithName:(NSString *)category desc:(NSString *)theDesc duration:(NSTimeInterval)theDuration {
// self = [super initWithNibName:@"EfficiencyViewController" bundle:nil];
if (self != nil) {
_category = category;
_desc = theDesc;
_duration = theDuration;
}
return self;
}
Problem: The values are simply not being passed. And also in this way, EVC is missing some major components, such as a button and a text label.