1

我想在我的项目中使用这个ECSlidingViewController。链接中的示例应用程序使用情节提要,但我想从 xibs 加载所有内容。我必须在 application:didFinishLaunchingWithOptions: 中实现什么来做到这一点?

来自示例应用程序的代码:

- (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;
}
4

2 回答 2

1

您可以从 nib 实例化它,而不是使用故事板来获取 UIViewController 的实例:

- (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;
}
于 2012-04-19T14:53:57.590 回答
0

试试这个适用于我的环境。

- (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;    
}

并且不要忘记添加

    [self.slidingViewController setAnchorRightRevealAmount:280.0f];

进入你的 firstviewcontroller 的 viewWillAppear 方法。

祝你好运

于 2012-05-15T22:17:17.077 回答