Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my delegation between two vc's not working?
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <pre><code> @protocol highScoreProtocol &lt;NSObject&gt; -(void)updateHighScore:(int) score; @end @interface ViewController : UIViewController &lt;UIAlertViewDelegate&gt; //i have this delegate implemented because i have a uiialertview @property (nonatomic) int score; @property (nonatomic, weak) id &lt;highScoreProtocol&gt; 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 &lt;highScoreProtocol&gt; @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&gt;[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. } </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload