Silver Challenge: Changing the Map Type


#1

Just wondering how bad of form this is considered, where I’m just kind of lazy in calling setMapType knowing that I setup the UISegmentedControl with exactly 3 segments in the order of the enums for the map types. Is there a better (but still semi-elegant) way to handle this.

- (IBAction)chooseMapType:(id)sender
{
    [worldView setMapType:[mapTypeSegments selectedSegmentIndex]];
}

#2

Nah, I like your way better. It beats creating an enumeration and putting together a switch statement.


#3

I like it too.I started down the if route for selectedSegmentIndex but it smelt bad so I came up with this too:

- (IBAction)mapType:(UISegmentedControl *)sender { [worldView setMapType:[sender selectedSegmentIndex]]; }


#4

I’m a real beginner here and though I’m not sure if I went about it the right way I was able to get a no-issue working build of this app in achieving the silver challenge.

Would like to know if this is not the proper way of coding.

To change the maptype I first went to the whereamiviewcontroller.h file and added this code

Then I went to the whereamiviewcontroller.m file and added this (got help from the apple documentation and the worldcities source code)

- (IBAction)setMapType:(id)sender { switch (((UISegmentedControl *)sender).selectedSegmentIndex) { case 0: { worldView.mapType = MKMapTypeStandard; break; } case 1: { worldView.mapType = MKMapTypeSatellite; break; } default: { worldView.mapType = MKMapTypeHybrid; break; } } }

Finally I went to xib file and inserted the segment control into the view and connected it to the file owner which sent the setMapType: event to value changed.

Would be great if anyone can tell me if this is way off or the right way of going about this.


#5

Hi

Did you add a IBOutlet in your WhereamiViewcontroller.h file ?
I can’t make it work without it …