Search code examples
iosuibuttonlevels

How to change the state of a button when an action is completed on another screen in Xcode?


How would I change the state of a button on a level select screen when a certain amount of points are achieved on the game itself? Basically, I want to have a button to appear when a level is completed, by getting a certain amount of points, on a different screen than the game screen that I got the score on. I want it to almost be like how it is in Angry Birds. I have already programed the levels to open from the level select screen and from the previous level when completed.


Solution

  • If the variable button screen is a different set of files or a different XIB, then you can call a custom -(id)init method to get the int or string of the score.

    Something like:

    //.h 
    
    int passedScore;
    
    //.m
    -(id)initwithscore:(int)score { 
    if (self = [super init]) {
    
    passedScore = score;
            }
    }  
    

    Then when you transition to the new view, call

    [newview alloc]initwithscore://score int]autorelease];
    

    Then it's a simple matter of seeing if the score is bigger or smaller than a given constant.

    if(//scoreint >= //const) {
    // do stuff 
    }