【问题标题】:Swift Xcode Button not showing next viewSwift Xcode Button 不显示下一个视图
【发布时间】:2015-01-08 21:06:34
【问题描述】:

我正在尝试编写一个简单地切换到下一个视图的按钮。所以我将第一个 ViewController 嵌入到导航控制器中,然后我拖入另一个视图控制器,创建了一个新的类名称 ViewController2 并将该类与第二个 ViewController 相关联,并为第二个视图控制器提供了故事板 ID:“view2”。然后在Button的函数中我添加了这段代码:

@IBAction func newGamePressed(sender: AnyObject) {

    let view2 = self.storyboard?.instantiateViewControllerWithIdentifier("view2") as   
ViewController2
    self.navigationController?.pushViewController(view2, animated: true)

}

但是,当我单击按钮时,实际上什么也没有发生!!!我做错了什么???

【问题讨论】:

  • 按钮连接到我假设的 IB 动作函数 newGamePressed?

标签: ios xcode swift uiviewcontroller uinavigationcontroller


【解决方案1】:
@IBAction func newGamePressed(sender: AnyObject) {
let VC1 = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("view2")
let navController = UINavigationController(rootViewController: VC1)
self.presentViewController(navController, animated:true, completion: nil)
}

试试这段代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-19
    • 2010-11-15
    • 1970-01-01
    • 2018-08-27
    • 1970-01-01
    • 2016-07-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多