0

我正在尝试以编程方式导航一些视图控制器。我已经在头文件中添加了 UINavigationControllerDelegate ......但是当我点击按钮时视图没有推出......谁能告诉我做错了什么???

    -(void)nextPage
    {
        NSLog(@"1234");
        infoViewController* info = [[infoViewController alloc] init];
        [self.navigationController pushViewController:info animated:YES];
        info = nil;
    }

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        self.navigationController.delegate = self;
        startFutureView = [[UIView alloc] initWithFrame:CGRectMake(160, 0, 320, 548)];
        startFutureView.backgroundColor = [UIColor redColor];
        [self.view addSubview:startFutureView];


        startPastView = [[UIView alloc] initWithFrame:CGRectMake(-160, 0, 320, 548)];
        startPastView.backgroundColor = [UIColor blueColor];
        [self.view addSubview:startPastView];

        startInfoBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        startInfoBtn.frame = CGRectMake(80, 137, 180, 180);
        [startInfoBtn addTarget:self action:@selector(nextPage)                         forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:startInfoBtn];

// Do any additional setup after loading the view, typically from a nib.
    }
4

1 回答 1

1

无需遵守UINavigationControllerDelegate即可推送视图控制器。我猜你的 navigationController 是零。

这样做的原因是您使用的是普通视图控制器,但您需要做的是创建视图控制器,然后将其包装在导航控制器中。例如,假设您现在以模态方式呈现 viewController:

UIViewController *viewController = [[UIViewController alloc] init];

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

这样做意味着 viewController 没有导航控制器,所以你需要这样做:

UIViewController *viewController = [[UIViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];

[self presentViewController:navigationController animated:YES completion:nil];
于 2013-04-27T18:05:02.323 回答