views:

137

answers:

2

Hi,

I am developing an iPhone application using XCode and I am kinda stuck with the functionality described in the subject of this post.

I want the map(using MapKit) to only load and display after I click a button. So, what code should I have under that my "(IBAction) showMap" function?

Whatever I could find online talks about unhiding the map. I want to only load the map when a button is clicked rather than loading the map in the background and simply unhiding it the click of the the button. Thanks !

~Susanth

A: 

Your button click should open a new view, which contains Map. Since that view does not exist until it's loaded (viewDidLoad, viewWillAppear), you are not loading map or displaying it beforehands.

- (IBAction)showMap:(id)sender
{
    self.mapController = [[MyMapViewController alloc]
        initWithNibName:@"MyMapViewController" bundle:nil];
    [self.mainView addSubview:mapController.view];
}

Many ways to do it... It takes time to load a map, so you might still consider loading it at background. Looks better (faster) for end-user.

JOM
A: 

use the below concept.

-(IBAction) showMap:(id)sender
{
     // Add your Map to current view
     [self.view addsubview:YOUR_MAPVIEW];
}

-(IBAction) hideMap:(id)sender
{
    [YOURMAPVIEW removeFromSuperView];
}

Here you can create the MapView either from XIB file or by writing code.

Hope this helps.

Jim.

Jim