In the current book I am reading, the author implements an IBAction for a slider in the following way (see below V001). To my eye, it seemed a little over complicated so I re-factored the code (V002). Am I right in thinking that sender is a pointer to the object that fired the event? Also, is there any downside to casting sender in the header, rather than leaving it as sender and casting it in the method body?
v001
-(IBAction)sliderChange:(id)sender {
UISlider *slider = (UISlider *)sender;
int progressAsInt = (int)([slider value] + 0.5f);
NSString *newText = [[NSString alloc] initWithFormat:@"%d", progressAsInt];
[sliderLabel setText:newText];
[newText release];
}
v002
-(IBAction)sliderChange:(UISlider*)sender {
NSString *newText = [[NSString alloc] initWithFormat:@"%d",(int)[sender value]];
[sliderLabel setText:newText];
[newText release];
}
gary