在 StoryBoard iOS 中将 UIContainerveiw 添加到 SlideViewNavigation 的问题

Posted

技术标签:

【中文标题】在 StoryBoard iOS 中将 UIContainerveiw 添加到 SlideViewNavigation 的问题【英文标题】:Issue in adding UIContainerveiw to SlideViewNavigation in StoryBoard iOS 【发布时间】:2016-02-08 07:45:30 【问题描述】:

我正在尝试通过 UIContainerView 在 SlidenavigationController 的情节提要中在视图底部添加一个持久按钮。

但是我在左滑出导航时得到一个空白视图(因为它在没有容器视图的情况下左滑出的表格内容列表工作正常)(used a third party Tool with ios-Slide-Menu)

故事板

ma​​inPageViewController 的代码

      - (void)viewDidLoad 
          [super viewDidLoad];


          UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
          [[ParseServiceManager GetInstance] initializeParse];



         [SlideNavigationController sharedInstance].leftMenu = [[UINavigationController alloc] initWithRootViewController:[[LeftMenuViewController alloc] init]];;
        
      [SlideNavigationController sharedInstance].rightMenu = [[UINavigationController alloc] initWithRootViewController:[[RightMenuViewController alloc] init]];
         [SlideNavigationController sharedInstance].menuRevealAnimationDuration = .18;
         [SlideNavigationController sharedInstance].enableSwipeGesture = FALSE;

         [[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidClose object:nil queue:nil usingBlock:^(NSNotification *note) 
    NSString *menu = note.userInfo[@"menu"];
    NSLog(@"Closed %@", menu);
];

         [[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidOpen object:nil queue:nil usingBlock:^(NSNotification *note) 
    NSString *menu = note.userInfo[@"menu"];
    NSLog(@"Opened %@", menu);
         ];

         [[NSNotificationCenter defaultCenter] addObserverForName:SlideNavigationControllerDidReveal object:nil queue:nil usingBlock:^(NSNotification *note) 
             NSString *menu = note.userInfo[@"menu"];
             NSLog(@"Revealed %@", menu);
         ];


     

控制台中的警告为:

SlideNavigationController 尚未初始化。要么在你的故事板中放置一个,要么在代码中初始化一个

如果有人在 CustomViewController 而不是 App delegate 中初始化 Slide-navigation 时遇到类似问题,请帮我解决这个问题!

【问题讨论】:

【参考方案1】:

我没有在 Storyboard 中添加任何 UiNavigationController(SlidenavigationController) 请参考屏幕截图,但像下面这样以编程方式初始化

从 Appdelegate 使用 SlideNavigationController 推送 LoginView

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle: nil];

LoginViewController *loginView = (LoginViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"LoginViewController"];
[loginView setModalPresentationStyle:UIModalTransitionStyleCrossDissolve];
SlideNavigationController * slideNavCtl = [[SlideNavigationController alloc] initWithRootViewController:loginView];
[self.window setRootViewController:slideNavCtl];

从 Appdelegate 使用 SlideNavigationController 推送 HomeView

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle: nil];
HomeViewController *homeView = (HomeViewController*)[mainStoryboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
[homeView setModalPresentationStyle:UIModalTransitionStyleCrossDissolve];
SlideNavigationController * slideNavCtl = [[SlideNavigationController alloc] initWithRootViewController:homeView];
[self.window setRootViewController:slideNavCtl];

LeftMenuViewController *leftMenu2 = (LeftMenuViewController*)[mainStoryboard
                                                                       instantiateViewControllerWithIdentifier: @"LeftMenuViewController"];
[SlideNavigationController sharedInstance].leftMenu = leftMenu2;

从 LOGINVIEW 登录后,我将使用 LeftMenuViewController 或 SideBarViewController 像这样推送到 HOMEVIEW 视图

 if(Login)

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone"     bundle: nil]; 
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier: @"HomeViewController"];


-----This is Important ,You need assign ur LeftMenu or SidebarViewcontroller here-----------------

LeftMenuViewController *leftMenu2 = (LeftMenuViewController*)[mainStoryboard                                                                     instantiateViewControllerWithIdentifier: @"LeftMenuViewController"];
[SlideNavigationController sharedInstance].leftMenu = leftMenu2;
 ------------------------------

[[SlideNavigationController sharedInstance] pushViewController:vc animated:YES]; 

 else 
nslog(@"Login Update failed")


【讨论】:

你救了我,谢谢。 永远欢迎?@iOSBadBoy

以上是关于在 StoryBoard iOS 中将 UIContainerveiw 添加到 SlideViewNavigation 的问题的主要内容,如果未能解决你的问题,请参考以下文章

在 Xcode 13 中将标签/按钮从 StoryBoard 连接到 ContentView

在 Xcode 6 中将 .storyboard 文件转换为原始 swift 代码

在 SWIFT 语言的 Storyboard 中将值从一个 ViewController 传递到另一个 ViewController

在storyboard中将动画应用于ModelVisual3D

IOS多语言切换2-storyboard

iOS 8 UITableView 背景颜色外观