MFSideMenu:UIScrollView不显示图像

时间:2013-06-24 14:52:19

标签: ios image uiscrollview viewcontroller

我在我的应用中使用MFSideMenu,其中4 UIScrollViews具有相同的代码我在tutorial 中使用4个不同的相同代码UIViewControllers SideMenuViewController- (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]; } } 选择时添加为子视图,这是我用来执行此操作的代码

{{1}}

这里的问题是视图控制器没有显示任何图像 它们显示UIScrollView背景,虽然 ,当我分开测试它们时 在另一个应用程序中 他们的工作

1 个答案:

答案 0 :(得分: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]; }
}