set target in viewDidLoad:
method.. like bellow..
- (void)viewDidLoad
{
.....
[segCtrl addTarget:self action:@selector(OnSegCtrlChanged:) forControlEvents:UIControlEventValueChanged];
}
Domanda
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 ?
Soluzione
set target in viewDidLoad:
method.. like bellow..
- (void)viewDidLoad
{
.....
[segCtrl addTarget:self action:@selector(OnSegCtrlChanged:) forControlEvents:UIControlEventValueChanged];
}
Altri suggerimenti
set it in loadView
method..
- (void)loadView
{
.....
[segCtrl addTarget:self action:@selector(OnSegCtrlChanged:) forControlEvents:UIControlEventValueChanged];
}
this might be better....