0

您好,下面是我正在使用的代码

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

任何帮助表示赞赏

感谢您

4

1 回答 1

1

进行 if 测试后,您必须添加 .png。使用您的示例,您现在所做的方式是将 9 附加到 club.png,这会给您 club.png9 而不是 club9,因此您的测试永远不会满意。

最简单的方法可能是不在第一行附加那个 .png,然后在你的 if 语句中,附加字母/数字和 .png,所以:

}else if([[currentCardDisplayed stringByAppendingString:@"9.png"]isEqualToString:currentCardName]){
    rule = @"drink9";
于 2012-12-11T20:18:27.993 回答