I am using MFSideMenu
in my app which have 4 UIScrollViews
with the same code I am using the same exact code in this tutorial in 4 different UIViewControllers
which added as subviews whenever they're chosen form the SideMenuViewController
and that is the code I am using to do that
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 1 //or any Index) {
UIViewController *centerController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"centerController"];
UIViewController *secondController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"secondController"];
[centerController.view addSubview:secondController.view];
UINavigationController *navigationController = self.menuContainerViewController.centerViewController;
NSArray *controllers = [NSArray arrayWithObject:centerController];
navigationController.viewControllers = controllers;
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed];
} }
The problem here is that the the view controllers don't show any images they show the UIScrollView background, though and when I test them separated in another application they work
After searching for a few hours I didn't find the solution anywhere, but I managed to fix it myself.
The problem happened because I shouldn't have used addSubView
and should have used my new view controller as a UINavigationController
instead.
Like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 1 /*or any Index*/) {
UIViewController *centerController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"centerController"];
UIViewController *secondController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"secondController"];
//Now we no longer need this-->[centerController.view addSubview:secondController.view];
UINavigationController *navigationController = self.menuContainerViewController.centerViewController;
//Edit starts here
NSArray *controllers = [NSArray arrayWithObject:secondController];
//Edit ends here
navigationController.viewControllers = controllers;
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed]; }
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.