SWRevealViewController FrontViewController没有加载,卡住为黑色,其他视图很好 [英] SWRevealViewController FrontViewController not loading, stuck as Black, other views fine

查看:147
本文介绍了SWRevealViewController FrontViewController没有加载,卡住为黑色,其他视图很好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试转换我们的应用程序以使用SWRevealViewController为应用程序的每一侧提供一个侧栏。但是,尽管在其中一个示例应用程序中遵循了代码,但我收到的错误是前视图的ViewController无法正常工作。 viewDidLoad被调用,但一切都是黑色。

I'm trying to transition our app to use SWRevealViewController to give us a side-bar on each side of the application. But despite following the code in one of the example apps, I'm getting an error where the ViewController for the front view doesn't work properly. viewDidLoad gets called, but everything remains black.

有趣的是,如果在我的viewDidLoad中,我将背景颜色设置为视图的红色,则会反映出来。但是来自原始故事板的Interface builder中的东西不是。

Interestingly, if in my viewDidLoad, I set the background colour to red of the view, this is reflected. But stuff in Interface builder from the original story board is not.

我在AppDelegate中使用的代码是:

The code I use in the AppDelegate is:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window = window;

    MainViewController *frontViewController = [[MainViewController alloc] init];
    RearViewController *rearViewController = [[RearViewController alloc] init];

    UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
    UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];

    SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
    revealController.delegate = self;

    RightViewController *rightViewController = rightViewController = [[RightViewController alloc] init];
    rightViewController.view.backgroundColor = [UIColor greenColor];

    revealController.rightViewController = rightViewController;

    //revealController.bounceBackOnOverdraw=NO;
    //revealController.stableDragOnOverdraw=YES;

    self.viewController = revealController;

    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

#pragma mark - SWRevealViewDelegate

- (id <UIViewControllerAnimatedTransitioning>)revealController:(SWRevealViewController *)revealController animationControllerForOperation:(SWRevealControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
{
    if ( operation != SWRevealControllerOperationReplaceRightController )
        return nil;

    if ( [toVC isKindOfClass:[RightViewController class]] )
    {
        if ( [(RightViewController*)toVC wantsCustomAnimation] )
        {
            id<UIViewControllerAnimatedTransitioning> animationController = [[CustomAnimationController alloc] init];
            return animationController;
        }
    }

    return nil;
}

这是Main.Storyboard,仅适用于MainViewController:

This is the Main.Storyboard which is just for the MainViewController:

当应用加载时,视图只是黑色。但我可以从左右边缘拖动并按预期方式查看侧边栏。所以只有FrontView才会出现黑色。我将一个NSLog()插入到ViewDidLoad中,该ViewDidLoad出现在控制台中, - (void)loadView {}中的一个显示View正在加载。

When the app loads, the view is just black. But I can drag from both the left and right edge and view the side bars as would be expected. So it's only the FrontView that is coming up black. I stuck an NSLog() into the ViewDidLoad, which appears in the console, as does one in -(void)loadView{}, which shows the View is loading.

如果我在viewDidLoad中放入一个 [self.view setBackgroundColor:[UIColor redColor]] 这会生效,这意味着它链接到视图,但它只是在视图中故事板没有出现。这很奇怪,因为故事板还包含一个NavigationController,它确实出现了(我想 - 除非那个导航控制器来自其他地方 - 我很确定它不是这样)。

If I put into the viewDidLoad a [self.view setBackgroundColor:[UIColor redColor]] this takes effect, meaning it is linked to the view, but it's just the view inside the storyboard is not appearing. Which is weird since the Storyboard also contains a NavigationController, which does appear (I think - unless that navigation controller is coming from somewhere else - which I'm pretty sure it isn't).

关于可能导致这种情况的任何想法?

Any thoughts on what might be causing this?

推荐答案

我有同样的事情发生。我在查看示例代码时修复了它。

I had the same thing going on. I fixed it while looking on the Example code.


  1. 在你的故事板中添加一个UIViewController

  2. 选择它和Identity Inspector中只使用'SWRevealViewController'作为类

  3. 将UITableViewController添加到你的故事板

  4. 现在选择你之前添加的ViewControler和right-点击一条线到你的TableViewController

  5. 选择'显示视图控制器集控制器'

  6. 点击新添加的Segue并在Attribute Inspector中更改标识符'sw_rear'

  7. 将任何自定义ViewController(例如'MyViewController')添加到故事板

  8. 选择它,然后转到菜单 - >编辑 - >嵌入 - >导航控制器

  9. 现在应该出现一个新的导航控制器

  10. 再次右击 - 从中​​绘制一条线第一个ViewController到你的新NavigationController

  11. 再次选择'显示视图控制器设置控制器'

  12. 现在将这个新Segue的标识符设置为'sw_front'

  1. In your Storyboard add a UIViewController
  2. Select it and in Identity Inspector just use 'SWRevealViewController' as class
  3. Add a UITableViewController to your story board
  4. Now select your previously added ViewControler and right-click-draw a line to your TableViewController
  5. Select 'reveal view controller set controller'
  6. Click on the newly added Segue and in Attribute Inspector change the identifier to 'sw_rear'
  7. Add any custom ViewController (for example 'MyViewController') to the story board
  8. Select it, then go to the Menu->Editor->Embed In->Navigation Controller
  9. Now a new Navigation Controller should appear
  10. Again right-click-draw a line from the first ViewController to your new NavigationController
  11. Again choose 'reveal view controller set controller'
  12. Now set the identifier of this new Segue to 'sw_front'

现在您有一个基本设置并且在运行时应用程序,您应该看到自定义的ViewController。现在必须添加菜单按钮。

Now you have a Basic Setup and when running your app, you should see your custom ViewController. Now the Button for the Menu has to be added.

在ViewControllers .m中添加以下内容:

In your ViewControllers .m add following:

@interface MyViewController ()
@property (nonatomic) IBOutlet UIBarButtonItem* revealButtonItem;
@end

- (void)viewDidLoad {
    [super viewDidLoad];

    [self customSetup];
}

- (void)customSetup
{
    SWRevealViewController *revealViewController = self.revealViewController;
    if ( revealViewController )
    {
        [self.revealButtonItem setTarget: self.revealViewController];
        [self.revealButtonItem setAction: @selector( revealToggle: )];
        [self.navigationController.navigationBar addGestureRecognizer: self.revealViewController.panGestureRecognizer];
    }
}

现在再次切换到故事板。将一个UIBarButtonItem添加到MyViewController。再次右键单击 - 从MyViewController中绘制一条线到NavigationBar中的这个新项。选择'revealButtonItem'。

Now again switch to the story board. Add a UIBarButtonItem to MyViewController. Again right-click-draw a line from MyViewController to this new item in the NavigationBar. Choose 'revealButtonItem'.

多数民众赞成吧!对要添加的每个ViewController重复上一步。您只需将它们从TableView右键单击绘图连接到每个添加的ViewControllers的新添加的NavigationController。要推动ViewControllers,只需选择'显示视图控制器推送控制器'。

Thats it! Repeat the last steps for every ViewController you want to add. You only have to connect them with right-click-drawing from the TableView to your newly added NavigationController of each of your added ViewControllers. To push the ViewControllers just select 'reveal view controller push controller'.

希望有所帮助!

这篇关于SWRevealViewController FrontViewController没有加载,卡住为黑色,其他视图很好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆