I have a container view, which uses a storyboard embed segue to load an embedded static table view. The segue ID is 'CONTAINER'.
When I run the following code, the prepareForSegue never actually gets called so no data is passed from the parent to the child.
- (void)viewDidLoad {
[super viewDidLoad];
if ([sGender isEqualToString:@"MALE"]) {
containerGender = @"MALE";
if ([containerGender isEqualToString:@"MALE"]){
NSLog(@"MALE");
}else{
NSLog(@"BROKEN");
}
}
else if ([sGender isEqualToString:@"FEMALE"]) {
containerGender = @"FEMALE";
}
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"CONTAINER"]) {
if([containerGender isEqualToString:@"MALE"]) {
if ([containerGender isEqualToString:@"MALE"]){
NSLog(@"MALE");
}else{
NSLog(@"BROKEN");
}
SportTableViewController *tableView = segue.destinationViewController;
tableView.sportGender = @"MALE";
}
else if ([containerGender isEqualToString:@"FEMALE"]){
SportTableViewController *tableView = segue.destinationViewController;
tableView.sportGender = @"FEMALE";
}
}
}
My question is:
a)Why is prepareForSegue not called? Does the Storyboard Embed Segue behave differently to a standard seque?
b)Is there a better way of passing data from the container view to the embedded table?
Also please ignore the messy implementation/various log tests, just my attempts to work out whats going wrong.
My question actually stems from a misunderstanding of how container views load their embedded views. Apparently, it all happens before viewDidLoad. That means my conversion of sGender into containerGender took place too late.
I fixed it by passing sGender to the embedded view directly. I had thought I'd already tried this, but yesterday was obviously a slow day ;).