I’m using someone elses code for my slider.
His code looks like this
UISlider *slider = (UISlider *)sender;
int number = [slider value];
NSString *string = [NSString stringWithFormat:@"%i", number];
label.text = string;
It shows the slider value, from 0 – 100.
It makes perfect sense, except that I’m confused with the first line of code which is the part after = , the (UISlider *)sender portion.
UISlider *slider = (UISlider *)sender;
If I understand correctly, he points the UISlider to the sender and stores it into the slider instance.
I guess my question is, what happened here? Was the UISlider *slider instance allocated.. what is going on exactly behind the scenes here and can this be done with other classes too?
Thank you to anyone that bothers with replying.
As far as i know the sender(in this case) is responsible for the event as it invokes the event most likely an
IBAction. Generally the sender is an untyped object which can represent any type of object. In this case the programmer is certain that its going to be invoked by aUISliderobject. So the type-casting is done to get an object of typeUISlider. This for example can also be done for aUIButtonwhere this line can be replaced byUIButton *button = (UIButton *)sender;