Search code examples
objective-cxcodeuiviewcontrollerdevelopment-environmentviewdidload

Xcode - how to make a level unlock system?


Hey guys I was just wondering how i could do this in Xcode. Any help would be appreciated

I would like to begin my level (that is already made) and then use the viewdidload (in my level view) to change a button in my level selector (separate view and xib to the level selector) this button needs to be changed into a round rect button that features a certain text that in this case will need to be "Level1". This button will need to be changed from a custom button which currently has a image of a Padlock to inform the user that the level is currently locked. Once that has been done I need to save the changes as a game default so that once the app has been closed it does not loose what levels you have unlocked

any help will be appreciated Thanks


Solution

  • well buttonType is a readonly property which can be set at the time of initialize as

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    

    the way to achieve what you want is just make two buttons and on the requirement just show or hide the buttons as

    [btn1 setHidden:YES];
    [btn2 setHidden:NO];
    

    EDIT: For this purpose of saving values without loosing there are lot of options .The easier one is the NSUserDefaluts Where you can store a value to a key string and retrieve back

    For changing the value from 2nd VC to 1st you have to implement delegate method on the 2nd VC to trigger an action in the 1st VC

    Tutorial on Delegation