Monotouch Achievements and leaderboard viewcontrollers
Im having an odd issue with dismissing my achievements and leaderboard viewcontrollers. The viewcontrollers display correctly and can be dismissed using the done button but only if you press it within about 15 secs of it being displayed, if you press done anytime after that my app just crashes. In the debugger i get a "unrecognized selector sent to instance" error.
I was guessing maybe the viewcontrollers are being garbage collected or something? I'd really appreciate any advice.
heres my code
public void checkAchievements(UIViewController view)
{
GKAchievementViewController gkview = new GKAchievementViewController();
view.PresentModalViewController(gkview,true);
gkview.Delegate = new gkviewdelegate();
}
public class gkviewdelegate : GKAchievementViewControllerDelegate
{
public override void DidFinish (GKAchievementViewController viewController)
{
viewController.Dis开发者_开发百科missModalViewControllerAnimated(true);
Console.WriteLine("Dismiss Leaderboard");
}
}
Your gkview is getting garbage collected. Change it to an instance variable instead in your class to keep a reference to it.
So your code should look a little like;
GKAchievementViewController gkview;
public void checkAchievements(UIViewController view)
{
gkview = new GKAchievementViewController();
view.PresentModalViewController(gkview,true);
gkview.Delegate = new gkviewdelegate();
}
精彩评论