Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setMasterViewController and setDetailViewController now remove former controller's view #49

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion Classes/MGSplitViewController.m
Expand Up @@ -961,6 +961,10 @@ - (void)setMasterViewController:(UIViewController *)master
if ([_viewControllers objectAtIndex:0] == newMaster) {
changed = NO;
} else {
// remove old master's view from the view hierarchy
// otherwise new master's view will be added in next layout without removing old view
// leaving the view while deallocating the vc will lead to crashes if the view uses the vc as datasource or delegate
[[[self masterViewController] view] removeFromSuperview];
[_viewControllers replaceObjectAtIndex:0 withObject:newMaster];
}

Expand Down Expand Up @@ -992,13 +996,17 @@ - (void)setDetailViewController:(UIViewController *)detail
if (!_viewControllers) {
_viewControllers = [[NSMutableArray alloc] initWithCapacity:2];
[_viewControllers addObject:[NSNull null]];
}
}

BOOL changed = YES;
if ([_viewControllers count] > 1) {
if ([_viewControllers objectAtIndex:1] == detail) {
changed = NO;
} else {
// remove old detail's view from the view hierarchy
// otherwise new detail's view will be added in next layout without removing old view
// leaving the view while deallocating the vc will lead to crashes if the view uses the vc as datasource or delegate
[[[self detailViewController] view] removeFromSuperview];
[_viewControllers replaceObjectAtIndex:1 withObject:detail];
}

Expand Down