简体   繁体   中英

ECSlidingViewController loading from XIB

I want to use this ECSlidingViewController in my project. Example app from link uses storyboards, but i want to load all from xibs. What i must implement in application:didFinishLaunchingWithOptions: to do this?

Code from example app:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  ECSlidingViewController *slidingViewController = (ECSlidingViewController *)self.window.rootViewController;
  UIStoryboard *storyboard;

  if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
  } else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
  }

  slidingViewController.topViewController = [storyboard instantiateViewControllerWithIdentifier:@"FirstTop"];

  return YES;
}

Instead of using storyboards to get an instance of the UIViewController, you can instantiate it from a nib:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  ECSlidingViewController *slidingViewController = [[ECSlidingViewController alloc] init];

  FirstTopViewController *firstTop = [[FirstTopViewController alloc] initWithNibName:@"FirstTop" bundle:nil];
  slidingViewController.topViewController = firstTop;

  self.window.rootViewController = slidingViewController

  return YES;
}

Try this that worked on my env.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  self.initialViewController = [[InitialViewController alloc] initWithNibName:@"InitialViewController" bundle:nil];
  self.window.rootViewController = self.initialViewController;

  ECSlidingViewController *slidingViewController = (ECSlidingViewController *)self.window.rootViewController;   
  FirstViewController *firstController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
  slidingViewController.topViewController = firstController;

  [self.window makeKeyAndVisible];
  return YES;    
}

and also do not forget to add

    [self.slidingViewController setAnchorRightRevealAmount:280.0f];

into your firstviewcontroller's viewWillAppear method.

Good luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM