Question

Here is the code

-(id) initWithNibName:(NSString*) nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
   ...
   [segCtrl addTarget:self action:@selector(OnSegCtrlChanged:) forControlEvents:UIControlEventValueChanged];
}

-(void)OnSegCtrlChanged:(id)sender
{
   if(segCtrl.selectedSegmentIndex==0)
   {
      [mapvw setMapType:MKMapTypeSatellite];
   }
   else if//....
}

My code to change the map image display looks just like that and sadly, nothing works at all after I compile and run the program. "Nothing works" means no corresponding maptype is displayed after I select an index from the segmented control on the screen.

[UPDATE] I would guess the initialization of the segmented control as I put in the InitWIthNibName is not correct as it is not the right place to start. If not, where should I leave it though ?

Was it helpful?

Solution

set target in viewDidLoad: method.. like bellow..

- (void)viewDidLoad
{
       .....
      [segCtrl addTarget:self action:@selector(OnSegCtrlChanged:) forControlEvents:UIControlEventValueChanged];
}

OTHER TIPS

set it in loadView method..

- (void)loadView
{
       .....
      [segCtrl addTarget:self action:@selector(OnSegCtrlChanged:) forControlEvents:UIControlEventValueChanged];
}

this might be better....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top