當我嘗試推送另一個控制器時,我遇到了UINavigationController
問題。Swift - UINavigation Controller變爲零
的AppDelegate
let testViewController:ProximityQuestionsIntroductionViewController = ProximityQuestionsIntroductionViewController();
self.navController = UINavigationController(rootViewController: testViewController);
self.window = UIWindow(frame: UIScreen.mainScreen().bounds);
self.window!.rootViewController = navController;
self.window!.backgroundColor = UIColor.whiteColor();
self.window!.makeKeyAndVisible();
return true
ProximityQuestionsIntroductionViewController
class ProximityQuestionsIntroductionViewController:UIViewController {
// Controls
var proximityIntroductionView:ProximityQuestionsIntroductionView!;
// Load components when the view is loaded
override func viewDidLoad() {
super.viewDidLoad();
print("nav in viewDidLoad : \(self.navigationController)");
//Hide Nav bar
self.navigationController?.navigationBarHidden = true;
// Set view
self.proximityIntroductionView = ProximityQuestionsIntroductionView(frame: self.view.frame);
self.view = self.proximityIntroductionView;
}
func start(){
print(self);
print("start in controller");
let nextController = ProximityQuestionsProgressViewController();
print("nav in start : \(self.navigationController)");
self.navigationController?.pushViewController(nextController, animated: true);
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
我打電話從一個按鈕被按下時,我ProximityQuestionsIntroductionView
start
。 在日誌中,我看到「導航在開始:無」,並且控制器不會更改。
欲瞭解更多信息:
自我是真正的
ProximityQuestionsIntroductionViewController
。導航欄真隱
所以導航控制器是viewDidLoad
確定,但不是在其他功能。
有人能告訴我爲什麼嗎?
謝謝!
編輯:AppDelegate中
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewControllerWithIdentifier("ProximityIntroduction");
self.navController = storyboard.instantiateViewControllerWithIdentifier("NavigationController") as! UINavigationController;
self.navController?.setViewControllers([initialViewController], animated: false)
self.window?.rootViewController = navController;
self.window?.makeKeyAndVisible();
我添加導航控制器到故事板並更改ID。但我仍然有對UINavigationController
一個nil
值的函數start
我試圖做所有我的項目沒有故事板,所以我有一個:'NSInvalidArgumentException',原因:'故事板()不包含視圖控制器與標識符'ProximityQuestionsIntroductionViewController'' –
那麼你使用xib進行設計? –
我以編程方式完成這一切。這是一個由其他人開始的項目,我不能讀故事板它是一團糟。 –