我SpriteKit
用 xcode 创建了一个应用程序,当游戏结束时,它会显示你的分数,我想添加将你的分数发布到 facebook 的功能。几乎我所有的代码都在MyScene.m
它无法访问的地方presentViewController
。只有我的 ViewController.m 文件可以访问它,所以我尝试从 Myscene.m 调用 Viewcontroller 中的实例方法,但我找不到这样做的方法。我发现从其他文件调用方法的唯一方法是使用+(void)
我认为的类方法。
Myscene.m:
if (location.x < 315 && location.x > 261 && location.y < 404 && location.y > 361) {
//if you click the post to facebook button (btw, location is a variable for where you tapped on the screen)
[ViewController facebook];
}
视图控制器.m:
+(void)facebook{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *facebook = [[SLComposeViewController alloc] init];
facebook = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebook setInitialText:@"initial text"];
}
}
这样就成功了,它正确调用了facebook类方法,但是当我放在[self presentViewController:facebook animated:YES]
setInitialText括号之后时,它给了我这个错误:选择器'presentViewController:animated:'没有已知的类方法
顺便说一句,它允许我presentViewController
在实例方法中使用,但我不能从类方法内部或我的 Myscene 文件中调用该方法。有没有办法从另一个文件调用实例方法,或者presentViewController
从类方法访问?谢谢