I have 2 applications in one, the first is skipped, why?

Hi, I am having problems using multiple if statements. Here is my code:

if ([itemOnSpecial caseInsensitiveCompare: @"yes"] == NSOrderedSame) { UILabel *specialLabel = (UILabel*) [cell viewWithTag:5]; specialLabel.text = specialPrice; [specialLabel setHidden:NO]; } //This statement is completely skipped if ([isOnBulkSpecial caseInsensitiveCompare:@"yes"] == NSOrderedSame) { UILabel *specialLabel = (UILabel*) [cell viewWithTag:5]; specialLabel.text = bulkSpecialPrice; [specialLabel setHidden:NO]; }else{ UILabel *specialLabel = (UILabel*) [cell viewWithTag:5]; [specialLabel setHidden:YES]; } 

Only the second if statement is taken into account. The first if statement is apparently completely ignored.

+4
source share
4 answers

if you change your code to:

 if ([itemOnSpecial caseInsensitiveCompare: @"yes"] == NSOrderedSame) { UILabel *specialLabel = (UILabel*) [cell viewWithTag:5]; specialLabel.text = specialPrice; [specialLabel setHidden:NO]; } else { if ([isOnBulkSpecial caseInsensitiveCompare:@"yes"] == NSOrderedSame) { UILabel *specialLabel = (UILabel*) [cell viewWithTag:5]; specialLabel.text = bulkSpecialPrice; [specialLabel setHidden:NO]; }else{ UILabel *specialLabel = (UILabel*) [cell viewWithTag:5]; [specialLabel setHidden:YES]; } } 

then the second if statement will be called only if the first has failed. Thus, the specialLabel.text property specialLabel.text not be changed twice, and the value will not be overridden in the second if

+3
source

Try to execute the code as follows:

 if ([itemOnSpecial isEqualToString: @"yes"] == NSOrderedSame) { UILabel *specialLabel = (UILabel*) [cell viewWithTag:5]; specialLabel.text = specialPrice; [specialLabel setHidden:NO]; if ([isOnBulkSpecial caseInsensitiveCompare:@"yes"] == NSOrderedSame) { UILabel *specialLabel = (UILabel*) [cell viewWithTag:5]; specialLabel.text = bulkSpecialPrice; [specialLabel setHidden:NO]; }else{ UILabel *specialLabel = (UILabel*) [cell viewWithTag:5]; [specialLabel setHidden:YES]; } } 

Or like this:

  if ([itemOnSpecial isEqualToString: @"yes"] == NSOrderedSame) { UILabel *specialLabel = (UILabel*) [cell viewWithTag:5]; specialLabel.text = specialPrice; [specialLabel setHidden:NO]; } else if ([isOnBulkSpecial caseInsensitiveCompare:@"yes"] == NSOrderedSame) { UILabel *specialLabel = (UILabel*) [cell viewWithTag:5]; specialLabel.text = bulkSpecialPrice; [specialLabel setHidden:NO]; }else{ UILabel *specialLabel = (UILabel*) [cell viewWithTag:5]; [specialLabel setHidden:YES]; } 

I do not understand your script, but the first if statement has nothing to do with the second in your code.

+2
source

The first statement will check a case-sensitive string, while the second statement will check a case-insensitive string.

when your itemOnSpecial's value is only β€œyes”, in this case it will be entered inside, otherwise it will be skipped, and in the second case your line will be @ β€œYes”, @ β€œYES”, @ β€œyEs”, @ β€œyeS” in all cases he will enter.

So I hope you understand my answer ...

0
source

Set a breakpoint on the first if condition and print the condition to see what it returns. Then complete the code.

ex.

 (lldb) p ([itemOnSpecial caseInsensitiveCompare: @"yes"] == 0) (bool) $1 = true 

Where NSOrderedSame == 0.

0
source

Source: https://habr.com/ru/post/1499079/


All Articles