0

我想以編程方式導航一些視圖控制器。我已經在頭文件中添加了UINavigationControllerDelegate ...但是當點擊按鈕時視圖沒有被推出...任何人都可以告訴我我做錯了什麼嗎?UINavigationController推送不正確

-(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. 
    } 
+0

變化登錄self.navigationController的的NSLog 。它是零嗎? – wattson12 2013-04-27 17:54:17

+1

只是將navcontrollerdelegate添加到頭文件是不夠的。你是否創建了navigationController的實例?它被分配給窗口的rootViewController嗎?如果您嘗試推送的viewController不是UINavigationController的rootviewcontroller,則不會發生任何事情。添加更多關於你的AppDelegate和ViewController的代碼將會有所幫助 – 2013-04-27 17:59:25

回答

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]; 
相關問題