MFSideMenu如何在另一个ViewController中加载

时间:2013-07-25 03:46:58

标签: ios objective-c mfslidemenu

我的应用程序基于LoginViewSecondView。我将在登录后显示SecondView。

我不想在MFSideMenuLoginView。我想在MFSideMenu中使用SecondView。我想在我的AppDelegate.m

中进行此操作
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];


 UIViewController *baseViewApp = [storyboard instantiateViewControllerWithIdentifier:@"MFSideMenuContainerViewController"];

 MFSideMenuContainerViewController *container = (MFSideMenuContainerViewController *)baseViewApp.view.window.rootViewController;

 //MFSideMenuContainerViewController *container = (MFSideMenuContainerViewController *)self.window.rootViewController;

 UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:@"navigationController"];

 UIViewController *leftSideMenuViewController = [storyboard instantiateViewControllerWithIdentifier:@"leftSideMenuViewController"];
 UIViewController *rightSideMenuViewController = [storyboard instantiateViewControllerWithIdentifier:@"rightSideMenuViewController"];


 [container setLeftMenuViewController:leftSideMenuViewController];
 [container setRightMenuViewController:rightSideMenuViewController];
 [container setCenterViewController:navigationController];

return YES;
}

在上图中,我从我的SideMenuContainerView(我想要加载MFSideMenu)中显示我的StoryBoard属性:

http://santoro.co/ios_deve.png

当我使用初始MFSideMenu开始构建我的应用时,ViewController正在运行。

我的SecondView并使用此行:

MFSideMenuContainerViewController *container = (MFSideMenuContainerViewController *)self.window.rootViewController;

但是当我尝试这个时:

UIViewController *baseViewApp = [storyboard instantiateViewControllerWithIdentifier:@"MFSideMenuContainerViewController"];

 MFSideMenuContainerViewController *container = (MFSideMenuContainerViewController *)baseViewApp.view.window.rootViewController;

MFSideMenu不起作用。

7 个答案:

答案 0 :(得分:3)

如果您尝试从app delegate访问它,您将在此处找到代码。诀窍是尝试获取UINavigationController。你可以在这里看到我通过窗口找到它。

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];

    MFSideMenuContainerViewController *container = (MFSideMenuContainerViewController *)self.window.rootViewController;
    HomeViewController * homeVC = [storyboard 
instantiateViewControllerWithIdentifier:@"HomeViewController"];

    NSArray *controllers = [NSArray arrayWithObject:homeVC];
    UINavigationController * navigationController = (UINavigationController* )container.centerViewController;
    navigationController.viewControllers = controllers;

答案 1 :(得分:0)

将一个新的UIViewController作为登录视图控制器引入MainStoryboard。在属性检查器中,将标识符更改为LoginViewController(或适当的东西)

- (void)viewDidAppear:(BOOL)animated
{
     [super viewDidAppear:animated];

      UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
      UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
      [vc setModalPresentationStyle:UIModalPresentationFullScreen];

      [self presentModalViewController:vc animated:YES];
}

成功登录后,只需关闭LoginViewController

答案 2 :(得分:0)

我通过将Lib更改为JASidePanels来修复此问题。

答案 3 :(得分:0)

 VideosViewController *videosViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"VideosViewController"];

            UINavigationController *navigationController = self.menuContainerViewController.centerViewController;
            NSArray *controllers = [NSArray arrayWithObject:videosViewController];
            navigationController.viewControllers = controllers;
    //VKJ

答案 4 :(得分:0)

UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:YourViewController];

MFSideMenuContainerViewController *container = (MFSideMenuContainerViewController *)self.view.window.rootViewController;
[container setCenterViewController:nav];

答案 5 :(得分:0)

不应该有任何链接(segues)或与主视图控制器和侧视图控制器的连接(可以设置主要和侧面),设置标识符其他故事板ID(MainMenuViewController ---> {{1} } {,mainVC ---> SideMenuViewController),sideVC import MainMenuViewController, SideMenuViewController, MFSideMenu,现在调用以下内容会移动视图:

loginview

答案 6 :(得分:0)

  1. 为登录和侧面创作创建两种方法
  2. 在Appdeleagate.h中添加此项
    • (无效)createLoginPage;
    • (无效)createSidemenuPage;
  3. 在Appdelegate.m中实现上述方法的定义。 例如: -
  4. 为Sidemenu创建名为SideMenuStoryBoardName的故事栏,并在该添加表视图中拖动视图控制器,这是侧视图。
  5. 使用名称为CenterStoryboardName创建home的故事标签,然后拖动视图控制器并设置该视图控制器的标识符。
  6. 使用appdelegate对象登录成功后调用createSidemenu方法。
  7. 代码:

    (void)createLoginPage
    {
        self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
        UIStoryboard *loginStoryBoard = [UIStoryboard storyboardWithName:LoginStoryBoardName bundle:nil];
        SigninViewController *signVC = [loginStoryBoard instantiateViewControllerWithIdentifier:SigninViewControllerIdentifier];
        UINavigationController* nav = [[UINavigationController alloc]initWithRootViewController:signVC];
        nav.navigationBar.hidden = YES;
        self.window.rootViewController = nav;
        [self.window makeKeyAndVisible];
    }
    
    (void)createSidemenuPage
    {
        //-- Left ViewController
        UIStoryboard *sideMenuSB = [UIStoryboard storyboardWithName:SideMenuStoryBoardName bundle:[NSBundle mainBundle]];
        SideMenu *sideMenuVC = [sideMenuSB instantiateViewControllerWithIdentifier:SideMenuIdentifier];
        //-- Center ViewController
        UIStoryboard *centerVC = [UIStoryboard storyboardWithName:CenterStoryboardName bundle:[NSBundle mainBundle]];
        UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:centerVC];
        MFSideMenuContainerViewController *container  =[MFSideMenuContainerViewController containerWithCenterViewController:navigationController leftMenuViewController:sideMenuVC rightMenuViewController:nil];
        self.window.rootViewController = container;
        [self.window makeKeyAndVisible];
    }