0

I'm trying to link a Mapbox example class to my IOS app. The example class implemented viewDidLoad method, so I assume I should instantiate this code inside a UIViewController file right?

But unfortunately I don't have that file. I'm using react native and I assume I should have at least AppDelegate and UIViewController files correct? But I don't have it. I only have the UIViewController instantiated in AppDelegate.m like so:

UIViewController *rootViewController = [UIViewController new];

rootViewController.view = rootView;
self.window.rootViewController = rootViewController;

Is this the place where I should "link" the example class so that the viewDidLoad will be triggered?

Community
  • 1
  • 1
user1885498
  • 823
  • 1
  • 8
  • 19

1 Answers1

2

In order to implement the viewDidLoad method you must create a subclass of UIViewController. In the AppDelegate.m file you are using a parent class, not a subclass.

Once you've created the UIViewController subclass (you could name it something like MapboxViewController) you would substitute it for the first line of code listed.

Instead of

UIViewController *rootViewController = [UIViewController new];

you'd have

MapboxViewController *rootViewController = [MapboxViewController new];

Here is a Stack Overflow that explains how to add a view controller in a ReactNative project. It's in Swift, but I think is still a good guide.

React-Native iOS - How can I navigate to a non-React-Native view (native iOS view controller) from a React-Native view with a button press?

David Borden
  • 131
  • 3
  • Thanks for the explanation. Actually I still haven't got it to work. Is it possible to just update the View part without updating the view controller? I'm trying to implement the mapbox example from a Rect native app, where I need to use the native language(objective c) to update the view but the example is always showing that i include the viewcontroller. But i don't know how to switch to a different view controller from react native – user1885498 Jun 05 '20 at 10:18