以下是我正在使用的代码
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];
我试图添加到最后的字母没有到达那里。我首先删除了一个字母,但是在我的if语句中我想检查是否我向该变量添加了一个不同的字母,它是否等于另一个字符串。
任何人都可以看到我出错的地方
下面的是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
感谢任何帮助
感谢你
答案 0 :(得分:1)
执行if测试后,必须添加.png。你现在的方式是使用你的例子,将9附加到club.png,这会给你club.png9而不是club9,所以你的测试永远不会满足。
最简单的方法可能是不在第一行附加.png,然后在if语句中附加字母/数字和.png,所以:
}else if([[currentCardDisplayed stringByAppendingString:@"9.png"]isEqualToString:currentCardName]){
rule = @"drink9";