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

时间:2018-09-10 08:41:25

标签: objective-c swift

我有一个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的类。

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:1)

以下是您在Objective-C中重写的代码:

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