【问题标题】:Xcode; Perform segue programmatically, for iOS 7代码;以编程方式执行 segue,适用于 iOS 7
【发布时间】:2016-08-26 02:21:59
【问题描述】:

我正在使用 Xcode 和 Swift 开发一个 iOS 应用程序。

我实际上是在使用这段代码来切换到另一个 ViewController:

let vc : AnyObject! = self.storyboard!.instantiateViewControllerWithIdentifier("FirstView")
if #available(iOS 8.0, *) {
    self.showViewController(vc as! UIViewController, sender: vc)
} else {
    // Fallback on earlier versions
}

这仅适用于 iOS 8 及更高版本。但我的应用也应该支持 iOS 7。

有人知道要支持 iOS 7 该怎么做吗?

【问题讨论】:

  • performSegueWithIdentifier("segueID", sender: nil)
  • 你要推送ViewController还是展示模型?

标签: ios swift segue


【解决方案1】:

presentViewController其实可以使用,只要改变ViewController的StoryboardID,调用这个函数就可以了

dispatch_async(dispatch_get_main_queue()) {
    let VC1 = self.storyboard!.instantiateViewControllerWithIdentifier("FirstView")
    self.presentViewController(VC1, animated:true, completion: nil)
}

【讨论】:

  • 谢谢,它有效。但是:为什么即使不使用UINavigationController也能工作?
  • 如果你没有 navController 你可以使用 self.presentViewController(VC1, animated:true, completion: nil)。我想它可以工作,因为 navController 在方法中被实例化了
猜你喜欢
  • 2017-10-03
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-12
相关资源
最近更新 更多