0

First, I am using storyboards for my navigation. I have come to a point where I am at a menu screen that goes off to 4 different views (just with a navigation controller) for 2 of those views I want it to check if the user has logged in and if not I want the LoginViewController/View brought up. I am very new to objective c/xcode and after searching for a solution this is what i have come up with. I do not know how to tie this in to my program. Does this just need to be linked to my button or am i completely off with what i am doing now?

if (self.appDelegate.userHasActiveLogin) {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"ViewController2"];
    [vc setModalPresentationStyle:UIModalPresentationFullScreen];

    [self presentModalViewController:vc animated:YES];}
else {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginController"];
    [vc setModalPresentationStyle:UIModalPresentationFullScreen];

    [self presentModalViewController:vc animated:YES];
}
4

1 回答 1

1

What you could do is to create manual segues in your storyboard.

按住 Ctrl 键从您的菜单控制器(橙色符号)拖动到子控制器,选择 push。单击 segue 并在属性检查器中为其指定一个标识符。现在您可以检查用户是否已登录,然后有条件[self performSegueWithIdentifier:@"logged in segue" sender:self];地调用您菜单的 VC。

条件是所有 VC 都必须在同一个故事板中,但我怀疑是这样。

于 2013-03-29T20:56:56.587 回答