我的应用程序基于LoginView
和SecondView
。我将在登录后显示SecondView。
我不想在MFSideMenu
上LoginView
。我想在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
不起作用。
答案 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)
代码:
(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];
}