romaonthego / REFrostedViewController

iOS 7/8 style blurred view controller that appears on top of your view controller.
MIT License
2.97k stars 494 forks source link

Open Viewcontroller from Appdelegate #98

Closed core-design closed 2 years ago

core-design commented 10 years ago

Evening, I just want to open a VIEW CONTROLLER from AppDelegate.

The example which I use > REFrostedViewController / Examples / storyboards /

My code:

//  DEMOAppDelegate.m
#import "DEMOAppDelegate.h"
#import "DEMOSecondViewController.h"

@implementation DEMOAppDelegate
- (void)applicationWillEnterForeground:(UIApplication *)application {
  DEMOSecondViewController *NewsTabController=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"secondController"];
    UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:NewsTabController];
    self.window.rootViewController = navController;
}

The view controller is opened, however, I can no longer open the menu?

core-design commented 10 years ago

With this option, I can now open the menu but get the error message below

    //AppDelegate.m
    #import "DEMOAppDelegate.h"
    #import "DEMOSecondViewController.h"
    #import "DEMONavigationController.h"
    #import "DEMOMenuViewController.h"
    #import "DEMOHomeViewController.h"
    @implementation DEMOAppDelegate

     - (void)applicationWillEnterForeground:(UIApplication *)application {
        //APP startet wieder aus dem Hintergrund...

        DEMOSecondViewController *NewsTabController=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"secondController"];
        UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:NewsTabController];
        DEMOMenuViewController *menuController = [[DEMOMenuViewController alloc] initWithStyle:UITableViewStylePlain];
        REFrostedViewController *frostedViewController = [[REFrostedViewController alloc] initWithContentViewController:navController menuViewController:menuController];
        frostedViewController.direction = REFrostedViewControllerDirectionLeft;

        self.window.rootViewController = frostedViewController;
    }

This is the error Message

2014-06-26 15:59:42.296 REFrostedViewControllerStoryboards[20515:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'

matteogus commented 8 years ago

Hi, I have the same problem, how did you solve it? I spent over 10 hours without any progress. Thanks.

core-design commented 8 years ago

Hi, this is my solution. Hope this helps you

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"Einsatzuebersicht"];
        NavigationViewController *navController=[[NavigationViewController alloc]initWithRootViewController:vc];
        MenueViewController *menuController = [[MenueViewController alloc] initWithStyle:UITableViewStylePlain];
        REFrostedViewController *frostedViewController = [[REFrostedViewController alloc] initWithContentViewController:navController menuViewController:menuController];
        frostedViewController.direction = REFrostedViewControllerDirectionLeft;
        frostedViewController.liveBlurBackgroundStyle = REFrostedViewControllerLiveBackgroundStyleLight;
        frostedViewController.liveBlur = YES;
        frostedViewController.delegate = self;

        self.window.rootViewController = frostedViewController;
        [self.window makeKeyAndVisible];
matteogus commented 8 years ago

Unfortunately, I get the same error when I run the code. Do you have other ideas or do you see something wrong in my code? Thanks a lot.

UIStoryboard` *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"homeController"];
    NavigationController *navController = [[NavigationController alloc] initWithRootViewController:vc];
    MenuViewController *menuController = [[MenuViewController alloc] initWithStyle:UITableViewStylePlain];
    REFrostedViewController *frostedViewController = [[REFrostedViewController alloc] initWithContentViewController:navController menuViewController:menuController];
    frostedViewController.direction = REFrostedViewControllerDirectionLeft;
    frostedViewController.liveBlurBackgroundStyle = REFrostedViewControllerLiveBackgroundStyleLight;
    frostedViewController.liveBlur = YES;
    frostedViewController.delegate = self;

    self.window.rootViewController = frostedViewController;
    [self.window makeKeyAndVisible];
core-design commented 8 years ago

What is the Error Message?

matteogus commented 8 years ago

The same error that you got in your second post

matteogus commented 8 years ago

This error precisely:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]' *\ First throw call stack: (0x1812d1900 0x18093ff80 0x1811babcc 0x1811c6674 0x1000cc058 0x1860f9f38 0x1861b8018 0x186274b70 0x186282030 0x185fb5c24 0x181288588 0x18128632c 0x18128675c 0x1811b5680 0x1826c4088 0x18602cd90 0x1000da6cc 0x180d568b8) libc++abi.dylib: terminating with uncaught exception of type NSException

Thanks core-design