簡體   English   中英

在presentViewController之后調用pushViewController不起作用

[英]Calling pushViewController after a presentViewController does not work

我正在展示我的視圖控制器 -

[self.navigationController presentViewController:self.thingContainerViewController animated:YES completion:nil]; //self.navigationController not nil here

這顯示了一個UITableView。 我想從這里推送導航堆棧上的VC。 但是self.navigationController在這一點上是零。 知道如何使這項工作?

[self.navigationController pushViewController:otherContainer animated:YES]; //self.navigationController is nil at this point

您需要將您正在呈現的視圖控制器包裝在導航控制器中,以便能夠使用push和pop方法。

所以第一步:

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.thingContainerViewController];

然后:

[self.navigationController presentViewController:navigationController animated:YES completion:nil];

如果你這樣做,你的代碼將起作用。

Swift 3 / Swift 4

首先,您需要設置要在其上顯示的導航控制器。然后在第二個視圖控制器上執行導航過程。

  • 這樣的例子

      let firstPresentVC = FirstVC(nibName:"FirstVC",bundle:nil) let navVC = UINavigationController(rootViewController:firstPresentVC) navVC.isNavigationBarHidden = true self.present(navVC, animated: true, completion:nil) 

現在你正在使用導航的當前堆棧

你可以在那之后推

let secondPushVC = secondPushVC(nibName:"secondPushVC",bundle:nil)
self.navigationController?.pushViewController(secondPushVC, animated: true)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM