![](/img/trans.png)
[英]Storyboard: how to set initial viewcontroller for UIPageViewController with storyboard?
[英]How to set conditional initial viewcontroller with storyboard
我想建立一個身份驗證過程,首先將用戶定向到登錄屏幕,在此用戶可以輸入其憑據,並且僅在成功通過身份驗證后才定向到主頁。
基於在線上找到的教程( http://sapandiwakar.in/programatically-set-the-initial-view-controller-using-storyboards/ ),我了解可以使用委托來這樣做。 但是我不知道
application:didFinishLaunchingWithOptions:
在哪里application:didFinishLaunchingWithOptions:
方法 viewcontroller
navigationcontroller
我怎么知道怎么做?
如果我正確理解您的問題。 如果用戶未登錄,則要將其引導到登錄視圖。否則,將其引導至主視圖。
您可以這樣嘗試:
這是一個示例:
在您的ContainerViewController.m中 :
- (void)viewDidLoad
{
if(isUserLoggedIn)
{
[self loadMainView];
}
else
{
[self loadLoginView];
}
}
- (void)loadMainView
{
UIViewController mainViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"MainView"];
[self addChildViewController:mainViewController];
[self.view addSubview:mainViewController.view];
[mainViewController didMoveToParentViewController:self];
[mainViewController.view setFrame:self.view.bounds];
}
- (void)loadLoginView
{
UIViewController loginViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LoginView"];
[self addChildViewController:loginViewController];
[self.view addSubview:loginViewController.view];
[loginViewController didMoveToParentViewController:self];
[loginViewController.view setFrame:self.view.bounds];
}
請注意:您不需要在容器和其他兩個視圖控制器之間設置segue。
希望這可以幫助。 :)
將您的登錄屏幕設置為初始視圖控制器,然后使用以下代碼成功將應用導航到主屏幕,然后執行登錄過程,否則留下相應的消息。
// you need to create UIStoryboard object by giving name of your storyboard
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
// here you need to create storyboard ID of perticular view where you need to navigate your app
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"viewContIdentifire"];
// if use presentViewController this will not enables you to go back to previous view
[self presentViewController:vc animated:NO completion:nil];
**// OR**
// using pushViewController lets you to go back to the previous view
[self.navigationController pushViewController:vc animated:YES];
希望這可以幫助 ..
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.