Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8799289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:17:06+00:00 2026-06-14T00:17:06+00:00

I have two view controllers. My first is my menu which contains my highscore

  • 0

I have two view controllers. My first is my menu which contains my highscore and a button which performs a modal segue to my second view controller which is my game. Whenever my player loses the game if he beat his highscore I want it to update on the menu.

Right now, when my player loses the game, I create a UIAlertView with 2 buttons, the first is main menu and the second is restart. Here is my simplified code with my attempting to update my high score via delegation.

        @protocol highScoreProtocol <NSObject>

        -(void)updateHighScore:(int) score;


        @end

        @interface ViewController : UIViewController <UIAlertViewDelegate> //i have this delegate implemented because i have a uiialertview
        @property (nonatomic) int score;
        @property (nonatomic, weak) id <highScoreProtocol> delegateHighScore;



        @implementation ViewController
        @synthesize score=_score;
        @synthesize delegateHighScore=_delegateHighScore;

            -(void)lostGame{
            [self.delegateHighScore updateHighScore:self.score]; //this is where i try to call the method that should update my high score if necessary but this doesn't actually work
        UIAlertView *losingScreen=[[UIAlertView alloc]initWithTitle:@"Game Over" message:[NSString stringWithFormat:@"Your Score Is %d", self.score] delegate:self cancelButtonTitle:@"Main Menu" otherButtonTitles:@"Restart", nil]; //once the user loses the game i have an alert view show giving the option to either restart the game or go to the main menu where the high score is
            }

        -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
              if (buttonIndex==0) {
                 //here i'm segueing back to my main menu because he would have pressed the 'main menu' button  [self performSegueWithIdentifier:@"MainMenu" sender:self];

            } else if (buttonIndex==1){
                //here i just reset my attributes and reset my level because he would have pressed the 'restart button'
            }
        }

    @end

            @interface MenuVC : UIViewController <highScoreProtocol>
            @property (weak, nonatomic) IBOutlet UILabel *labelHighScore; //the labelhighscore is the highscore number

            @end


@implementation MenuVC

- (void)viewDidLoad
{
    [super viewDidLoad];
    ViewController *vc=[[ViewController alloc]init];
    vc.delegateHighScore=self;//here is set the delegate as myself which i think i'm supposed to do for some reason

}

-(void)updateHighScore:(int)score{
    if (score>[self.labelHighScore.text integerValue]) { 
        self.labelHighScore.text=[NSString stringWithFormat:@"%d", score];
    }
    NSLog(@"does this method even run");

// this is the method that updates the highscore which I want to run
// but it doesn't, notice I even made an 'nslog' to see if the method
// even runs but I never ever even got a log out in the debugger,
// so this method never runs.
}

If I just need a little help, or if I’m doing everything completely wrong and going about this task the wrong way, please say.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:17:07+00:00Added an answer on June 14, 2026 at 12:17 am

    This doesn’t work because this:

    ViewController *vc=[[ViewController alloc]init];
    vc.delegateHighScore=self;
    

    Instantiates a NEW viewcontroller, that has completely nothing to do with the one you are interacting with.

    I assume you are using storyboards so, create an identifier for your viewcontroller (on the interface builder -> select your viewcontroller -> identity inspector tab -> write a name where it says Storyboard ID)

    And then add this instead of the previous code:

    ViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"yourIdentifier"];
    vc.delegateHighScore = self;
    

    Edit:

    Add this to your button action (but delete the segue from the interface builder AND delete this code from the viewDidLoad)

    ViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"yourIdentifier"];
    vc.delegateHighScore = self;
    [self presentModalViewController:vc animated:YES];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two view controllers which should work like described below: First view controller
I have two view controllers. First view controller is added on window in which
I have application where i have two view controllers my first view and second
I have two view controllers. I'm on first, and when I press the button,
I have two view controllers, in which I am using navigation controller to navigate
I have two objects, both of which are view controllers. The first (Ill call
I have two view controllers that allow changes to the Address Book. The first
I have two view controllers in a tabbar which can both edit data. Therefore,
I have a view that has two buttons(First and Second) and one hidden field.
guys. I have two view controllers with two uiwebviews. Here is my code: First

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.