Skip to content

Instantly share code, notes, and snippets.

@zh-se
Created July 13, 2015 07:37
Show Gist options
  • Save zh-se/13b436235d4ad7b3bd46 to your computer and use it in GitHub Desktop.
Save zh-se/13b436235d4ad7b3bd46 to your computer and use it in GitHub Desktop.
// 1. A property has the same name as a segue identifier in XIB
@property (nonatomic) ChildViewController1 *childController1;
@property (nonatomic) ChildViewController2 *childController2;
// #pragma mark - UIViewController
- (void)prepareForSegue:(UIStoryboardSegue *)segue
sender:(id)sender
{
[super prepareForSegue:segue sender:sender];
// 2. All known destination controllers assigned to properties
if ([self respondsToSelector:NSSelectorFromString(segue.identifier)]) {
[self setValue:segue.destinationViewController forKey:segue.identifier];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// 3. Controllers already available bc viewDidLoad is called after prepareForSegue
self.childController1.view.backgroundColor = [UIColor redColor];
self.childController2.view.backgroundColor = [UIColor blueColor];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment