代码之家  ›  专栏  ›  技术社区  ›  anon

需要帮助将这段代码从Swift转换成Objective-C吗

  •  -6
  • anon  · 技术社区  · 6 年前

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

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

    2 回复  |  直到 6 年前
        1
  •  1
  •   Fogmeister    6 年前

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

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:NULL];
    UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"OverrideClass"];
    [self presentViewController:controller animated:YES completion:NULL];
    
        2
  •  1
  •   Pete Morris    6 年前

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

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