This is a migrated thread and some comments may be shown as answers.

Trouble adding MKMapView to a UIView

4 Answers 72 Views
NativeScript Insiders
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
TJ
Top achievements
Rank 1
TJ asked on 09 Feb 2015, 01:27 PM
Hey all,

I created a simple iOS app with Objective-C where I just place a MKMapView in a UIView. I've been trying to replicate this in NativeScript and I can't get the map to appear. Here's my code:

<Page navigatedTo="load">
</Page>
exports.load = function( args ) {
    var iosView = args.object.ios._page._view;
    var map = MKMapView.alloc().initWithFrame( CGRectMake( 0, 0, 1000, 1000 ) );
    iosView.addSubview( map );
};

This code runs without any errors, but I see no map. Any ideas what might be up here?

Thanks,
TJ

4 Answers, 1 is accepted

Sort by
0
Accepted
Erjan Gavalji
Telerik team
answered on 13 Feb 2015, 12:28 PM
Hi TJ,

Being the container of the application, the page module is very complex. It in turn makes the retrieval of its actual platform-specific view complex both in terms of a proper event in the lifecycle and in terms of nested components.

Thus, you'd better use a panel as a container of the map.

Please, check the attached example.

Hope that helps,
Erjan Gavalji
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
TJ
Top achievements
Rank 1
answered on 13 Feb 2015, 02:01 PM
Thanks Erjan,

That makes sense and your example solved my problem. I didn't realize the panels had loaded events, and just fyi that doesn't appear to be documented: https://github.com/NativeScript/docs/tree/master/ApiReference/ui/panels/stack-panel.

Thanks again,
TJ
0
Erjan Gavalji
Telerik team
answered on 13 Feb 2015, 02:33 PM
Well,

The StackPanel class inherits the Panel one, which in turn inherits the View class. The View class has

  • onLoaded()
  • onUnloaded()

instance functions, which act as the actual event handlers of the class.

Well, I must admit this is by no means easy to find. The NativeScript documentation has a huge room for improvement.

We'll get there soon though, just some more time...

Cheers,
Erjan Gavalji
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
TJ
Top achievements
Rank 1
answered on 13 Feb 2015, 09:32 PM
Yep no worries. I was going to create a GitHub issue to list inherited properties/method/events/etc but it seems Valio beat me to it: https://github.com/NativeScript/docs/issues/34 :)
Tags
NativeScript Insiders
Asked by
TJ
Top achievements
Rank 1
Answers by
Erjan Gavalji
Telerik team
TJ
Top achievements
Rank 1
Share this question
or