【问题标题】:Need help converting this bit of code from Swift to Objective-C需要帮助将这段代码从 Swift 转换为 Objective-C
【发布时间】:2018-09-10 08:41:25
【问题描述】:

我有一个 Objective-C 应用程序,我需要从代码中加载另一个 VC 类。我已经设法在另一个 Swift 应用程序中实现了这一点。

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "OverrideClass")
self.present(controller, animated: true, completion: nil)

我需要帮助为 ObjC 创建一个相同的函数。它基本上是使用代码中提到的故事板标识符加载 VC 的类。

【问题讨论】:

  • 任何 Objective-C 教程都会向您展示其语法是如何工作的。代码几乎相同,只是语法不同。
  • 以下链接可能对您有用stackoverflow.com/a/16134703/5184217

标签: objective-c swift


【解决方案1】:

代码非常相似,只是语法不同......

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:NULL];
UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"OverrideClass"];
[self presentViewController:controller animated:YES completion:NULL];

【讨论】:

    【解决方案2】:

    这是您提供的用 Objective-C 重写的代码:

    UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:NULL];
    UIViewController * controller = [storyboard instantiateViewControllerWithIdentifier:@"OverrideClass"];
    [self presentViewController:controller animated:YES completion:NULL];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-12
      • 1970-01-01
      相关资源
      最近更新 更多