Pregunta

Hello below is the code i am using

currentCardDisplayed = [NSMutableString stringWithFormat:@"%@.png", [[cardsShuffled objectAtIndex:currentCard-1] substringToIndex:[[cardsShuffled objectAtIndex:currentCard-1] length]-1]];

NSString *rule;

if([[currentCardDisplayed stringByAppendingString:@"e"] isEqualToString:currentCardName]){
    rule = @"drink";
}else if([[currentCardDisplayed stringByAppendingString:@"2"]isEqualToString:currentCardName]){
    rule = @"drink2";
}else if([[currentCardDisplayed stringByAppendingString:@"3"]isEqualToString:currentCardName]){
    rule = @"drink3";
}else if([[currentCardDisplayed stringByAppendingString:@"4"]isEqualToString:currentCardName]){
    rule = @"drink4";
}else if([[currentCardDisplayed stringByAppendingString:@"5"]isEqualToString:currentCardName]){
    rule = @"drink5";
}else if([[currentCardDisplayed stringByAppendingString:@"6"]isEqualToString:currentCardName]){
    rule = @"drink6";
}else if([[currentCardDisplayed stringByAppendingString:@"7"]isEqualToString:currentCardName]){
    rule = @"drink7";
}else if([[currentCardDisplayed stringByAppendingString:@"8"]isEqualToString:currentCardName]){
    rule = @"drink8";
}else if([[currentCardDisplayed stringByAppendingString:@"9"]isEqualToString:currentCardName]){
    rule = @"drink9";
}else if([[currentCardDisplayed stringByAppendingString:@"0"]isEqualToString:currentCardName]){
    rule = @"drink10";
}else if([[currentCardDisplayed stringByAppendingString:@"k"]isEqualToString:currentCardName]){
    rule = @"drinkjack";
}else if([[currentCardDisplayed stringByAppendingString:@"n"]isEqualToString:currentCardName]){
    rule = @"drinkqueen";
}else if([[currentCardDisplayed stringByAppendingString:@"g"]isEqualToString:currentCardName]){
    rule = @"drinkking";
}
NSLog(@" %@ ", currentCardDisplayed);
NSLog(@" %@ ", currentCardName);
NSLog(@"%@", rule);
NSLog(@" %@", [cardsShuffled objectAtIndex:currentCard-1]);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Rules" message:rule delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];

[alert show];

the letters i am trying to add to the end are not getting there. i remove a letter at first, but then in my if statement i want to check if i add a different letter to that variable is it equal to the other string.

Can anyone see where i am going wrong

below is the sample output from the nslogs

2012-12-11 20:06:50.853 Kings_1.03[4915:c07]  club.png 
2012-12-11 20:06:50.855 Kings_1.03[4915:c07]  club9.png 
2012-12-11 20:06:50.857 Kings_1.03[4915:c07] (null)
2012-12-11 20:06:50.858 Kings_1.03[4915:c07]  club9

ANy help is appreciated

Thanking YOu

¿Fue útil?

Solución

You have to add the .png after you do the if tests. The way you're doing in now, using your example, is to append the 9 to club.png, which gives you club.png9 not club9, so your test is never satisfied.

The easiest way would probably to not append that .png in the first line, and then in your if statements, append both the letter/number and .png, so:

}else if([[currentCardDisplayed stringByAppendingString:@"9.png"]isEqualToString:currentCardName]){
    rule = @"drink9";
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top