C# 示例中的 GKScore ReportScores 方法
GKScore ReportScores method in C# example
谁能告诉我如何使用 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 a
variable', value' or
method 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# 编写 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 a
variable',value' or
method 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);
});