0

I am using this code to show leader boards:

 -(void)viewscores:(SPEvent*)event

   {
     tempVC = [[UIViewController alloc] init];


    GKLeaderboardViewController* leaderboardController = [[[GKLeaderboardViewController alloc] init] autorelease];
    if (leaderboardController != nil)
    {
        leaderboardController.leaderboardDelegate = self;
        UIView *sparrowView = self.stage.nativeView; // take care that self.stage != nil!
        [sparrowView addSubview:tempVC.view];
        //[tempVC.view addSubview:leaderboardController.view];
        [tempVC presentModalViewController:leaderboardController animated:YES];
    }
}

- (void)animationDidStop:(NSString*)animationID finished:(BOOL)finished context:(void *)context
{
    for(UIView *subview in [tempVC.view subviews]) {
        [subview removeFromSuperview];
    }
    [tempVC.view.superview removeFromSuperview];
    [tempVC release];
}

-(void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController*)viewController
{
    CGRect frame = viewController.view.frame;
    // [tempVC dismissModalViewControllerAnimated:YES];
    [UIView beginAnimations:@"curldoup" context:nil];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:.5];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    // [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.stage.nativeView cache:YES];
    frame.origin.y = 420;
    viewController.view.frame = frame;
    [UIView commitAnimations];
    //[viewController.view removeFromSuperview];

When I click DONE on the leader boards, the background turns gray and the app gets messed up.

I am VERY POSITIVE that this is due to the line:

frame.origin.y = 420;

Since an iPhone screen is 420. Can anyone please assist me on the correct number to put there?

Any ideas appreciated, Thanks a lot!

Raoul
  • 85
  • 2
  • 10
  • Why not just do dismissModalViewController since you are using presentModalViewController to present that view. – SimplyKiwi May 11 '12 at 02:46
  • So where do I place that code? – Raoul May 11 '12 at 10:49
  • In your -(void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController*)viewController { method – SimplyKiwi May 11 '12 at 19:44
  • Can you please tell me the entire code I need to add? I am confused on what your trying to say, please make it simpler to understand, like put the code after method. Thanks – Raoul May 11 '12 at 22:24

1 Answers1

1

You should present it like this:

- (void)showGCLeaderboard {
leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != NULL)
{
    leaderboardController.category = kLeaderboardID; 
    leaderboardController.leaderboardDelegate = self;
    [self presentModalViewController:leaderboardController animated:YES];
}

}

So just do this to dismiss it:

- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController {
    [self dismissModalViewControllerAnimated:YES];
    [viewController release];
}

OR

Since you are trying to do this on an iPad, you can get fancy with it by using UIPopovers but that is up to you and it is not necessary.

SimplyKiwi
  • 12,376
  • 22
  • 105
  • 191
  • undeclared code... leaderboardController and others. Can you see my post about the cod I used and see the correct code I need to add? Thanks – Raoul May 12 '12 at 18:38
  • Whoops, add this to your .h: GKLeaderboardViewController *leaderboardController; – SimplyKiwi May 12 '12 at 19:20
  • use of undeclared identifier: leaderboardController.category = kLeaderboardID; leaderboardController.leaderboardDelegate = self – Raoul May 12 '12 at 19:25
  • 1
    #define kLeaderboardID @"001" Then add GKLeaderboardViewControllerDelegate in your .h. But honestly, you should be able to fix these issues by yourself since they are quite trivial. Are you familiar with how Objective-C works? – SimplyKiwi May 12 '12 at 21:01
  • If this code helped please hit the checkmark until its green and up vote it if it really helped you! – SimplyKiwi May 13 '12 at 20:39
  • I fixed it. But not from the code YOU Provided me, should I still click checkmark to know that this post it answered? – Raoul May 14 '12 at 20:20
  • In a way Yes and No, if it doesn't you specifically then its up to you. Even if my code doesn't help you in particular, it could help others so in that case, so you could accept it also. – SimplyKiwi May 14 '12 at 20:34