Data not save in NSUserDefaults
<p>i having a problem with my NSUserdefaults. When i type in the name in the textbox and click on the highscore the application will not response anything and the keypad will still be on the screen. When i tried to load the data, it say that the data for name is nil. The score that i have is 90. Can someone please tell me what is wrong with my coding. </p>

<p>Lots of thanks.</p>

<pre><code>-(IBAction)savehighscore_button {


    int i, ii = -1;

    struct high_score {
        NSString *name;
        int highScore;
    };

    struct high_score structArray[10];

    NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];

    for (i=0; i&lt;10; i++) {

        if ([userPreferences stringForKey :[NSString stringWithFormat:@"highScoreNameEntry%d",i]]!=nil &amp;&amp; [userPreferences stringForKey :[NSString stringWithFormat:@"highScoreEntry%d"]]!=nil) {
        structArray[i].name= [userPreferences stringForKey:[NSString stringWithFormat:@"highScoreNameEntry%d",i]];
            structArray[i].highScore = [userPreferences integerForKey:[NSString stringWithFormat:@"highScoreEntry%d",i]];
            ii = i;
        }
    }
    if (myScore &gt;0) {
        for (i==ii; i&gt;=0; i--) {
            if (myScore &gt; structArray[i].highScore) {
                if (i&lt;9) {
                    structArray[i+1] = structArray[i];
                    structArray[i].name = nametextbox.text;
                    structArray[i].highScore = myScore;

                    if (i==ii &amp;&amp; i&lt;9) {
                        structArray[i+1].name = nametextbox.text;
                        structArray[i+1].highScore = myScore;
                        ii=i+i;
                    }

                    else if(i==ii &amp;&amp; i&lt;9) {
                        structArray[i+1].name = nametextbox.text;
                        structArray[i+1].highScore = myScore;
                        ii=i+1;
                    }
                }
            }

            if (ii==-1 &amp;&amp; myScore &gt;0) {
                structArray[0].name = nametextbox.text;
                structArray[0].highScore = myScore;
                ii=0;
            }
            for (i=0; i&lt;=ii; i++) {
                [userPreferences setObject:structArray[i].name forKey:[NSString stringWithFormat:@"highScoreNameEntry%d",i]];
                [userPreferences setInteger:structArray[i].highScore forKey:[NSString stringWithFormat:@"highScoreEntry%d",i]];
            }
        }
    }

}
</code></pre>
