0

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

4

1 回答 1

0

搜索了几个小时后,我没有在任何地方找到解决方案,但我设法自己修复了它。

问题的发生是因为我不应该使用addSubView并且应该使用我的新视图控制器作为UINavigationController替代。

像这样:

- (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]; }
}
于 2013-06-25T13:19:17.820 回答