Hi all,
I have a small question which might be easy to answer for one of you all.
I have a 'rootViewController' that has an header, container and footer
(All with costum backgrounds etc)
I have several buttons on the rootViewController which trigger a costum segue to load lets say homeViewcontroller or secondViewController into the container.
Now I what I would like to do is.. From homeViewController I'd like to put a button that will go to previewViewController
But it must be loaded into the container of rootViewController.
But the button that will trigger the segue is not in the rootViewController but in the homeViewController.
Anyone understands what I mean ? And can help out? It would be great.
All I can get to is go to the previewViewController from the home, but it will lose the 'layout' of the rootViewController.
This is my rootViewController
header file
And my rootSegue
Its very basic for now.
I have a small question which might be easy to answer for one of you all.
I have a 'rootViewController' that has an header, container and footer
(All with costum backgrounds etc)
I have several buttons on the rootViewController which trigger a costum segue to load lets say homeViewcontroller or secondViewController into the container.
Now I what I would like to do is.. From homeViewController I'd like to put a button that will go to previewViewController
But it must be loaded into the container of rootViewController.
But the button that will trigger the segue is not in the rootViewController but in the homeViewController.
Anyone understands what I mean ? And can help out? It would be great.
All I can get to is go to the previewViewController from the home, but it will lose the 'layout' of the rootViewController.
This is my rootViewController
Code:
#pragma mark - Segue
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if (![segue isKindOfClass:[rootSegue class]]) {
[super prepareForSegue:segue sender:sender];
return;
}
self.oldViewController = self.destinationViewController;
//if view controller isn't already contained in the viewControllers-Dictionary
if (![self.viewControllersByIdentifier objectForKey:segue.identifier]) {
[self.viewControllersByIdentifier setObject:segue.destinationViewController forKey:segue.identifier];
}
self.destinationIdentifier = segue.identifier;
self.destinationViewController = [self.viewControllersByIdentifier objectForKey:self.destinationIdentifier];
[[NSNotificationCenter defaultCenter] postNotificationName:rootViewControllerChangedNotification object:nil];
}
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
if ([self.destinationIdentifier isEqual:identifier]) {
//Dont perform segue, if visible ViewController is already the destination ViewController
[[NSNotificationCenter defaultCenter] postNotificationName: rootControllerViewControllerAlreadyVisibleNotification object:nil];
return NO;
}
return YES;
}
Code:
@interface rootViewController : UIViewController
@property (weak,nonatomic) UIViewController *destinationViewController;
@property (strong, nonatomic) NSString *destinationIdentifier;
@property (strong, nonatomic) UIViewController *oldViewController;
@property (weak, nonatomic) IBOutlet UIView *container;
@end
And my rootSegue
Code:
- (void) perform {
rootViewController *newViewcontroller = (rootViewController *)self.sourceViewController;
UIViewController *destinationViewController = (UIViewController *) newViewcontroller.destinationViewController;
//remove old viewController
if (newViewcontroller.oldViewController) {
[newViewcontroller.oldViewController willMoveToParentViewController:nil];
[newViewcontroller.oldViewController.view removeFromSuperview];
[newViewcontroller.oldViewController removeFromParentViewController];
}
destinationViewController.view.frame = newViewcontroller.container.bounds;
[newViewcontroller addChildViewController:destinationViewController];
[newViewcontroller.container addSubview:destinationViewController.view];
[newViewcontroller didMoveToParentViewController:newViewcontroller];
}
Its very basic for now.
Last edited: