xcode로 SpriteKit
에 앱을 만들었습니다. 게임이 끝나면 점수가 표시되고 점수를 페이스 북에 게시하려면이 기능을 추가하고 싶습니다. 거의 모든 내 코드는 MyScene.m
에 있으며 어디서 액세스 할 수 없는지 presentViewController
입니다. 내 ViewController.m 파일 만 액세스 할 수 있으므로 Viewcontroller에서 Myscene.m의 인스턴스 메서드를 호출 해 보았습니다.하지만이를 수행 할 방법을 찾을 수 없습니다. 다른 파일에서 메서드를 호출하는 유일한 방법은 +(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];
}
ViewController.m :
+(void)facebook{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *facebook = [[SLComposeViewController alloc] init];
facebook = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebook setInitialText:@"initial text"];
}
}
그래서
근무하고 올바르게 페이스 북의 클래스 메소드라고,하지만 난 setInitialText 브래킷 후 [self presentViewController:facebook animated:YES]
을 넣을 때, 나 에게이 오류를 준다 : 알 수없는 클래스 메서드를 selector에 'presentViewController : animated :'
presentViewController
인스턴스 메서드에서 있지만 클래스 메서드 또는 내 Myscene 파일에서 해당 메서드를 호출 할 수 없습니다. 다른 파일에서 인스턴스 메서드를 호출하거나 클래스 메서드에서 presentViewController
에 액세스 할 수있는 방법이 있습니까? 감사합니다
허용되는 대답은이 문제에 영향을 미치지 않지만 언급 한 오류는 클래스에 인스턴스 메서드를 호출하려는 시도가 원인입니다. 클래스 메소드 ('+ (void) facebook')의'self '는'ViewController * yourViewController'가 아니라'[ViewController class]'를 가리 킵니다. 그리고'ViewController' 클래스는 뷰 컨트롤러를 표현할 수 없습니다. – CloakedEddy