gpt4 book ai didi

c# - C# 示例中的 GKScore ReportScores 方法

转载 作者:行者123 更新时间:2023-11-29 02:21:06 25 4
gpt4 key购买 nike

谁能告诉我如何使用 C# 编写 ReportScores 示例?我发现了很多关于它是如何用 objective-C 而不是 C# 编写的例子,而且转换器很贵。我一直在使用旧的、现在已弃用的 GKScore ReportScore,并尝试迁移到新的 GKScore ReportScores。我在 ReportScores 方法的 Action 参数上苦苦挣扎。这是我的代码:

GKScore scoreReporter = new GKScore (category);
scoreReporter.Value = score;
GKScore[] allScores = new GKScore[] { scoreReporter };
scoreReporter.ReportScores(allScores, new Action<NSError> ((error) => {

在最后一行编译时出错:

Error CS0176: Static member `MonoTouch.GameKit.GKScore.ReportScores 
(MonoTouch.GameKit.GKScore[], System.Action
<MonoTouch.Foundation.NSError>)'
cannot be accessed with an instance reference,
qualify it with a type name instead

如果我尝试先在这行之前:

Action<NSError> completionHandler = new Action<NSError> ();
scoreReporter.ReportScores(allScores, completionHandler

它在第一行出错:

method name expected 

如果我尝试从“new Action()”中删除“new”,它会出错:

Error CS0119: Expression denotes a type', where avariable', value' ormethod group' was expected

我应该如何用 C# 编写它!?

谢谢

最佳答案

没关系,我找到了答案。我最终这样做了:

GKScore scoreReporter = new GKScore (category);
scoreReporter.Value = score;
GKScore[] allScores = new GKScore[] { scoreReporter };
GKScore.ReportScores(allScores, (x) => {
if(x == null){
new UIAlertView ("Score reported", "Score Reported successfully", null, "OK", null).Show ();
}
else{
new UIAlertView ("Score Reported Failed", "Score Reported Failed", null, "OK", null).Show ();
}
NSThread.SleepFor(1);
});

关于c# - C# 示例中的 GKScore ReportScores 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28127574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com