【问题标题】:How to use pushFrontViewController with SWRevealViewController如何将 pushFrontViewController 与 SWRevealViewController 一起使用
【发布时间】:2014-10-09 16:08:13
【问题描述】:

我正在使用 SWRevealViewController 库。使用 AppCoda 教程(也很好),我已经成功地让它工作得很好。但是,我现在已经配置了一个“设置”屏幕,我想在其中将内容保存到 Core Data 中,然后将屏幕弹出回主屏幕。

因为设置屏幕有一个嵌入式导航栏,而 iOS 7 不允许导航栏内有导航栏,所以我使用了一种变通方法来调用它。

// Get the view controller
UIViewController *vcNew = [[UIStoryboard storyboardWithName:@"Main" bundle:NULL] instantiateViewControllerWithIdentifier:vcName];


// Swap out the Front view controller and display
[self.revealViewController setFrontViewController:vcNew];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];

我现在不知道该怎么做,是如何弹出这个。

标准: [self.navigationController popViewControllerAnimated:YES]; 和 [selfdismissViewControllerAnimated:YES 完成:nil];

似乎根本不起作用。

我从 John Lluch 的文档中注意到,现在有必要使用“pushFrontViewController”。但是,我不清楚如何做到这一点。

我假设我使用这样的东西:

[self.revealViewController pushFrontViewController:<(UIViewController *)> animated:<(BOOL)>]

但是 UIViewController 的身份是什么?

【问题讨论】:

    标签: ios objective-c uiviewcontroller swrevealviewcontroller


    【解决方案1】:

    线索当然在我问的问题中:

    我只是简单地使用了 sw_rear viewcontroller 的标识符并执行了以下操作。

    // Get the view controller
    UIViewController *vcNew = [[UIStoryboard storyboardWithName:@"Main" bundle:NULL] instantiateViewControllerWithIdentifier:@"SW_FRONT_ID_GOES_HERE!!!"];
    
    // Swap out the Front view controller and display
    [self.revealViewController setFrontViewController:vcNew];
    [self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
    

    简单...

    【讨论】:

      【解决方案2】:

      我不知道 SWRevealController 库,但在顶部放置新视图控制器的通用方法就是展示它...

      *vcNew = [[UIStoryboard storyboardWithName:@"Main" bundle:NULL] instantiateViewControllerWithIdentifier:vcName];
      // btw, if you're inside another view controller from the same storyboard, you can
      // use self.storyboard instead of the longer 'storyboardWithName'
      [self presentViewController:vcNew animated:YES completion:^{
          // this block runs when the present animation completes
          // you can usually do nothing in here
      }];
      

      如果由于某种原因这不起作用,请尝试在您的 SWReveal 库容器上显示它,就像这样(我怀疑您是否需要这样做)...

      [self.revealViewController presentViewController:vcNew // ... and so on
      

      如果您保留指向它的指针,则可以从呈现它的同一视图控制器中将其关闭,否则,通常更容易不保留指针并在完成后让设置 vc 自行关闭...

      // in SettingsViewController.m
      // when it's time to dismiss
      [self dismissViewControllerAnimated:YES completion:^{}];
      

      另外,只是重读您的帖子,我猜测应该在文档 pushFrontViewController 中使用哪个视图控制器将是您想要在前面的那个,即vcNew

      【讨论】:

        【解决方案3】:

        Popview 是您要导航的视图。根据您在 (UIViewController *) 位置的问题,viewcontroller 的对象将放置。

        像这样:

        MainVC *mv = [[MainVC alloc]init];
            UINavigationController *mnav = [[UINavigationController alloc]initWithRootViewController:mv];
            [reveaself.revealViewController pushFrontViewController:mnav animated:YES];
        

        这样你就可以像流行音乐一样导航了。

        【讨论】:

        • 非常感谢 Hiren。
        猜你喜欢
        • 2015-05-21
        • 2014-07-01
        • 2016-05-03
        • 2020-11-13
        • 2021-01-02
        • 1970-01-01
        • 2023-03-13
        • 2014-09-25
        相关资源
        最近更新 更多