Trouble adding MKMapView to a UIView

5 posts, 1 answers
  1. TJ
    TJ avatar
    58 posts
    Member since:
    Aug 2013

    Posted 09 Feb 2015 Link to this post

    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
  2. Answer
    Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 13 Feb 2015 Link to this post

    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.

     
  3. TJ
    TJ avatar
    58 posts
    Member since:
    Aug 2013

    Posted 13 Feb 2015 in reply to Erjan Gavalji Link to this post

    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
  4. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 13 Feb 2015 Link to this post

    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.

     
  5. TJ
    TJ avatar
    58 posts
    Member since:
    Aug 2013

    Posted 13 Feb 2015 in reply to Erjan Gavalji Link to this post

    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 :)
Back to Top