I have a simple function to see if the button touched is the same as the text of a label:
- (IBAction) checkIt:(id)sender{
UIButton *button = (UIButton *)sender;
if(button.getText() == randomNumber.text){
randomNumber.text = @"Nice.";
}
else{
randomNumber.text = @"Try Again";
}
}
Where “randomNumber” is a label. However, this doesn’t work. I’m a Cocoa/Objective-C beginner and I’m not sure what the proper syntax is.
I’m open to any addition information you would like/think is helpful to idiots like me. 🙂
Four buttons are mapped to this function: Cow, Pig, Frog, Sheep. The “randomNumber” label is randomized from an array of strings “Cow,Frog”…
This will never work because this is not the right way to compare strings. ‘==’ only compares the memory address, the NSString method
isEqualToStringactually compares the strings.Also, I would get the button text by using the property, titleLabel.text. So, I would try like this: