1

我是 xcode 和 objective-c 的初学者,我只是按照我在 youtube 上观看的课程中的所有步骤来创建刽子手游戏。但是当我输入错误的字母时,切换大小写出现错误,应该更新图像,但是当我输入第二个错误的字母时,它只是转到默认大小写并重新开始。(但在正确的情况下,字符串(WrongLetter)的长度应该加1,然后输入case 2,以此类推)。

这个词是:科罗拉多(对于那些将运行程序的人)

if (match==NO)
{
    self.WrongLetter = [self.WrongLetter stringByReplacingOccurrencesOfString:LetterToCheck withString: @""];

    self.WrongLetter = [self.WrongLetter stringByAppendingString:LetterToCheck];


     switch  (self.WrongLetter.length) {
         case 1:
         {self.HangMan.image = [UIImage imageNamed:@"head"];
             break;}
         case 2:{
            self.HangMan.image = [UIImage imageNamed:@"HB"];
             break;}
         case 3:{
            self.HangMan.image = [UIImage imageNamed:@"HBA"];
             break;}
         case 4:{
            self.HangMan.image = [UIImage imageNamed:@"HBAs"];
             break;}
         case 5:{
            self.HangMan.image = [UIImage imageNamed:@"HBAL"];
             break;}
         case 6:{
            self.HangMan.image = [UIImage imageNamed:@"CompleteMan"];
             break;}

         default:{
            [self SetHangManWord:self.CorrectWord];
             break; }

    } }

这是我的项目: http ://www.2shared.com/file/BLHIQ6kQ/HM_online.html

这是 youtube 上的课程: http ://www.youtube.com/watch?v=I63BSGsFnEw

我将不胜感激任何帮助 :)

4

1 回答 1

3

改变这个:

@property (weak, nonatomic) IBOutlet NSString *WrongLetter;

对此:

@property (strong, nonatomic) NSString *WrongLetter;

The WrongLetter property gets released too soon. And on second iteration it's just null.
It's a bad practice to name your variables with first letter capitalized. Usually class names get first letter capital.

于 2013-02-10T16:23:51.800 回答