无法移动到另一个视图控制器

时间:2014-07-02 17:57:52

标签: ios uiviewcontroller

我试图从第一个视图控制器移动 - >第二视图控制器。然而,似乎没有任何事情发生。

主要来自登录页面,因此一旦我成功登录,我就不需要返回该页面。我现在正试着从一个按钮来检查。

我有2节课。

  1. signInPage
  2. optionsScreen
  3. 我需要从1> 2


    在signInPage.m内部

    #import "optionsScreen.h"
    
    - (IBAction)moveToNext:(id)sender {
    
    
        optionsScreen *aSecondPageController =
        [[optionsScreen  alloc]
         initWithNibName:@"optionsScreen"
         bundle:nil];
    
        [self.navigationController pushViewController:aSecondPageController animated:YES];
    
    //    [aSecondPageController release];
    
    
    }
    

    故事板的屏幕截图

    https://drive.google.com/file/d/0B1y7ao4cGAYKaU0yRlVxcVg2bzA/edit?usp=sharing

    解决方案:

    - (IBAction)moveToNext:(id)sender {
    
    
        NSString * storyboardName = @"Main_iPhone";
    
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
        UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"optionsScreen"];
        [self presentViewController:vc animated:YES completion:nil];
    
    }
    

2 个答案:

答案 0 :(得分:0)

在storyboard中添加导航视图控制器。作为根视图控制器 - 也许默认情况下它是表视图控制器,所以删除它 - 设置第一个视图控制器。添加导航控制器,您可以根据需要将多个视图控制器推送到导航堆栈。

答案 1 :(得分:0)

我认为您尝试做的是以模态方式呈现视图控制器,而不是将其推入堆栈(不存在)。相反,你应该这样做。默认情况下,这不会显示后退按钮,因此您必须手动添加一个按钮:

optionsScreen *aSecondPageController = [[optionsScreen alloc] initWithNibName:@"optionsScreen" bundle:nil];

[self presentViewController:aSecondPageController animated:YES completion:nil];

要返回,在optionsScreen视图控制器中,您需要某种后退按钮吗?所以你可以在viewDidLoad中执行此操作:

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(backPressed:);

然后,您必须创建一个名为backPressed:

的新方法
-(void)backPressed:(id)sender {

    [self dismissViewControllerAnimated:YES completion:nil];
}

编辑:事实证明你正在尝试按我上面的说法进行操作。我将离开导航控制器位以供将来参考。

如果您尝试使用导航控制器来推送您的选项,默认情况下给您一个后退按钮,那么首先,在您的故事板中,单击您的登录视图控制器,然后在顶部的菜单栏转到Editor > Embed In... > Navigation Controller。然后在视图控制器切换方法中,您可以执行之前尝试的操作

optionsScreen *aSecondPageController = [[optionsScreen alloc] initWithNibName:@"optionsScreen" bundle:nil];

[self.navigationController pushViewController:aSecondPageController animated:YES];
相关问题