Hey,
I'm just starting to learn iPhone programming and come across one thing that seemed a little strange that I thought I would ask about.
http://blog.objectgraph.com/index.php/2009/04/03/iphone-sdk-30-playing-with-map-kit-part-2/
I was going through this website and completed the same program. When I was finished I seen some code that I thought might work a bit better.
I seen this and then changed it to this:
I removed the need to have the IBOutlet in the code and (I thought) made it a bit simpler. This restricts the changeType method to only be linked with UISegmentedControl objects in the XIB file but that's all it was being used for anyway.
Looking around I often see alot of delegate methods using (id)sender. Is there any particulate reason for this?
The only reason I can think you would use (id)sender is if objects of different class types would be calling that delegate method, other then that using the particular class is Ok.
I'm mainly asking because I see it around alot, the use of (id)sender - and wonder if I should be doing the same thing for any reason.
Thanks
I'm just starting to learn iPhone programming and come across one thing that seemed a little strange that I thought I would ask about.
http://blog.objectgraph.com/index.php/2009/04/03/iphone-sdk-30-playing-with-map-kit-part-2/
I was going through this website and completed the same program. When I was finished I seen some code that I thought might work a bit better.
Code:
@interface MainViewController : UIViewController <FlipsideViewControllerDelegate,MKReverseGeocoderDelegate,MKMapViewDelegate> {
MKMapView *mapView;
MKReverseGeocoder *geoCoder;
MKPlacemark *mPlacemark;
IBOutlet UISegmentedControl *mapType;
}
- (IBAction)changeType:(id) sender;
--------------------------------------------
- (IBAction)changeType:(id)sender{
if(mapType.selectedSegmentIndex==0){
mapView.mapType=MKMapTypeStandard;
}
else if (mapType.selectedSegmentIndex==1){
mapView.mapType=MKMapTypeSatellite;
}
else if (mapType.selectedSegmentIndex==2){
mapView.mapType=MKMapTypeHybrid;
}
}
I seen this and then changed it to this:
Code:
@interface MainViewController : UIViewController <FlipsideViewControllerDelegate,MKReverseGeocoderDelegate,MKMapViewDelegate> {
MKMapView *mapView;
MKReverseGeocoder *geoCoder;
MKPlacemark *mPlacemark;
}
- (IBAction)changeType:(UISegmentedControl*) sender;
--------------------------------------------
- (IBAction)changeType:(UISegmentedControl*)sender{
if(sender.selectedSegmentIndex==0){
mapView.mapType=MKMapTypeStandard;
}
else if (sender.selectedSegmentIndex==1){
mapView.mapType=MKMapTypeSatellite;
}
else if (sender.selectedSegmentIndex==2){
mapView.mapType=MKMapTypeHybrid;
}
}
I removed the need to have the IBOutlet in the code and (I thought) made it a bit simpler. This restricts the changeType method to only be linked with UISegmentedControl objects in the XIB file but that's all it was being used for anyway.
Looking around I often see alot of delegate methods using (id)sender. Is there any particulate reason for this?
The only reason I can think you would use (id)sender is if objects of different class types would be calling that delegate method, other then that using the particular class is Ok.
I'm mainly asking because I see it around alot, the use of (id)sender - and wonder if I should be doing the same thing for any reason.
Thanks