我想在我的项目中使用此ECSlidingViewController。来自链接的示例app使用故事板,但我想从xib加载所有内容。 我必须在应用程序中实现: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;
}
答案 0 :(得分:1)
您可以从笔尖实例化它,而不是使用故事板来获取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;
}
答案 1 :(得分: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方法。
祝你好运