【问题标题】:How to import a UIViewController in AppDelegate using swift如何使用 swift 在 AppDelegate 中导入 UIViewController
【发布时间】:2015-01-14 08:23:37
【问题描述】:

我有一个名为 FirstViewController.swift 的 UIViewController 类,我想在名为 MySample.How 的应用程序中将其导入 AppDelegate.swift 中,以便在 AppDelegate.swift 中导入 UIViewController.swift。我用谷歌搜索,但找不到有效的答案。

提前致谢。

【问题讨论】:

  • 你在使用故事板 ya XIB?
  • 我正在使用故事板。有没有像 Swift 中的 Objective C 等效项中的 #import "FirstViewController.h" 之类的东西
  • 不,在 Swift 项目中你不需要导入其他类——它们是隐式可见的
  • 好的,谢谢你的回答

标签: ios iphone swift uiviewcontroller


【解决方案1】:

试试这个代码:

    func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?) -> Bool {
    var rootViewController = self.window!.rootViewController as UINavigationController
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    var FirstViewController = mainStoryboard.instantiateViewControllerWithIdentifier("StoryBoardID") as FirstViewController
    rootViewController.pushToViewController(FirstViewController, animated: true)

    return true

  }

【讨论】:

  • 任何让提问者朝着正确方向前进的答案都是有帮助的,但请尝试在您的答案中提及任何限制、假设或简化。简洁是可以接受的,但更全面的解释会更好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-11
  • 2021-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-27
相关资源
最近更新 更多