![](/img/trans.png)
[英]Swift - Function in other view controller is not being called (protocol / delegate)
[英]Presenting view controller function not being called iOS Swift
對於此問題,在其中運行此代碼的視圖控制器位於Login.storyboard IB文件中。 我嘗試提供的視圖控制器位於Main.storyboard IB文件中。 下面的代碼是我用來從一個視圖控制器轉換到另一個視圖控制器的代碼。
func presentNextView() {
let mainSb: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let screenAfterLogin: UIViewController = mainSb.instantiateViewControllerWithIdentifier("MainContainerView") as! UIViewController
self.presentViewController(screenAfterLogin, animated: true, completion: nil)
}
運行該應用程序,我在presentNextView函數中執行的3行上設置3個斷點。 調用第一行,調用第二行,但不調用第三行,並且不顯示下一個屏幕。 xCode目前有問題嗎?
在github上簽出項目: https : //github.com/joshuarcher/RecallBeta
問題在於文件“ HardLoginViewController.swift”
func presentNextView() {
let mainSb: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let screenAfterLogin: SecondVC = mainSb.instantiateViewControllerWithIdentifier("SecondVC") as SecondVC
let navigationController = UINavigationController(rootViewController: screenAfterLogin)
presentViewController(navigationController, animated: true, completion: nil)
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
presentNextView()
}
func presentNextView() {
let mainSb: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let screenAfterLogin: SecondVC = mainSb.instantiateViewControllerWithIdentifier("SecondVC") as SecondVC
let navigationController = UINavigationController(rootViewController: screenAfterLogin)
presentViewController(navigationController, animated: true, completion: nil)
}
}
import UIKit
class SecondVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.title="Second Screen"
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.