【问题标题】:Is it possible to call Objective c view controller class from swift class using storyboard?是否可以使用情节提要从 swift 类中调用 Objective c 视图控制器类?
【发布时间】:2017-09-08 04:15:14
【问题描述】:

是否可以从 swift 类文件中推送目标 c 视图控制器?

我尝试了如下所述,

import UIKit
class DashboardViewController: UIViewController {

   @IBOutlet weak var submitButton: UIButton!
 class func instantiate() -> DashboardViewController {
    let storyboard = UIStoryboard(name: "DashboardView", bundle: Bundle.main)
    return storyboard.instantiateViewController(withIdentifier: "dashboardVC") as! DashboardViewController
}
override func viewDidLoad() {
    super.viewDidLoad()

}
@IBAction func userClickedSubmitButton(_ sender: Any) {
  //let dashboardDetailsVC = DashboardDetailsViewController.instantiate()  
  //self.navigationController?.pushViewController(dashboardDetailsVC!, animated: true)

    let storyBoard: UIStoryboard = UIStoryboard(name: "DashboardDetails", bundle: nil)
    let newViewController = storyBoard.instantiateViewController(withIdentifier: "dashDetails") as! DashboardDetailsViewController
    self.present(newViewController, animated: true, completion: nil)
}

收到错误为“使用未声明的类型'DashboardDetailsViewController'”。我什至尝试导入类文件。有什么办法可以解决这个问题吗? TIA。

【问题讨论】:

  • 你试过使用桥接头吗?
  • 我完全忘记在 bring header 类中添加我的 header。谢谢。

标签: ios objective-c swift uiviewcontroller


【解决方案1】:

创建一个新文件"ModuleName-Bridging-Header.h"并在这个文件中 import "YourObjectiveCViewController.h" 然后尝试打开它。

希望对你有帮助。

【讨论】:

  • @user579911 如果我的解决方案解决了您的问题,您可以投票并将其标记为答案。谢谢
猜你喜欢
  • 1970-01-01
  • 2018-04-22
  • 2013-10-21
  • 1970-01-01
  • 2017-07-08
  • 1970-01-01
  • 1970-01-01
  • 2014-02-17
  • 1970-01-01
相关资源
最近更新 更多