-6

I have an Objective-C app where I need to load another VC class from within the code. I've managed to accomplish this in another Swift app.

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

I need help creating an identical function for ObjC. It's basically loading the class of the VC with the storyboard identifier mentioned in the code.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306

2 Answers2

1

The code is very similar just with a different syntax...

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:NULL];
UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"OverrideClass"];
[self presentViewController:controller animated:YES completion:NULL];
Fogmeister
  • 76,236
  • 42
  • 207
  • 306
1

Here's the code you provided re-written in Objective-C:

UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:NULL];
UIViewController * controller = [storyboard instantiateViewControllerWithIdentifier:@"OverrideClass"];
[self presentViewController:controller animated:YES completion:NULL];
Pete Morris
  • 1,472
  • 8
  • 13