titleForState:UIControlStateNorma
Hi all,
I am new to Objective C and trying hard to understand WHY things are done the way they are done. Apparently books skip the WHY part and they just tell me WHAT to do. Here is my question. The code for knowing what button was clicked is:
-(IBAction) clicked: (id)sender{
NSString *titleOfButton = [sender titleForState:UIControlStateNormal];
NSString *newLabelText = [[NSString alloc]initWithFormat:@"%@", titleOfButton];
labelsText.text=newLabelText;
[newLabelText release];
}
I am wondering why involve titleForState:UIControlStateNormal, newLabelText and initWithFormat. Why not straight forward
labelsText.text = [sender titleForState:UIControlStateNormal];
I am pretty sure there is a valid reason. Please tell me what is it?
|