iOS compare button title to string

后端 未结 4 1859
渐次进展
渐次进展 2020-12-11 18:18

I\'m just learning how to code so thanks for your patience on this simple question.

Here\'s my code:

- (IBAction)buttonWasPressed:(id)sender {  
            


        
4条回答
  •  猫巷女王i
    2020-12-11 19:10

    in objective-c you can't compare strings using "==", instead you should use the method isEqualToString from the NSString class to compare a string with another.

    if ([buttonName isEqualToString: @"Button 1"]) {
      // do something
    }
    

提交回复
热议问题