gpt4 book ai didi

ios - 无法使用 xcode beta 6.3 将 View Controller 推送到导航 Controller

转载 作者:行者123 更新时间:2023-11-29 02:12:13 26 4
gpt4 key购买 nike

我正在尝试将 View Controller 推送到导航 Controller 中。该代码在 xcode 6.1 中似乎是正确的。但是当我将项目更改为 xcode beta6.3 时,xcode 要求我将类型运算符更改为 as!。现在我无法将 View Controller 推送到导航 Controller 中

//delegate method
func sendIndex(row : Int){

switch row {

case 0:

if(!isCurrentMoneyVc){
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let moneySummaryVC: MoneySummaryVC = storyboard.instantiateViewControllerWithIdentifier("moneyVC") as MoneySummaryVC
//self.navigationController?.pushViewController(moneySummaryVC, animated: true)
self.navigationController?.setViewControllers([moneySummaryVC], animated: true)
}else{
hideMenu()
}

case 1:

if(!isCurrentAboutVc){
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let moneySummaryVC1: AccountsVC = storyboard.instantiateViewControllerWithIdentifier("account") as AccountsVC

self.navigationController?.pushViewController(moneySummaryVC1, animated: true)
}else{
hideMenu()
}

case 2:

if(!isCurrentTransactionVc){
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let moneySummaryVC2: Transaction = storyboard.instantiateViewControllerWithIdentifier("transact") as Transaction
self.navigationController?.pushViewController(moneySummaryVC2, animated: true)
}else{
hideMenu()
}

default:
println("no index")


}

}

最佳答案

从技术上讲,如果在 Storyboard 中找不到,您的 viewcontroller 可以为 nil,这可能是 xcode 提示的原因。从 Storyboard 中引用 View Controller 并推送它的更好方法:

if let moneySummaryVC2 = storyboard.instantiateViewControllerWithIdentifier("transact") as? Transaction {
self.navigationController?.pushViewController(moneySummaryVC2, animated: true)
}

现在我们只在成功创建 View Controller 常量 moneySummaryVC2 时尝试推送 View Controller ,这意味着在 Storyboard中找到了 View Controller ID。不要忘记处理未找到 View Controller 的情况(日志记录或其他)。

关于ios - 无法使用 xcode beta 6.3 将 View Controller 推送到导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29165472/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com