Sprite kit 从场景中显示另一个视图控制器
我正试图从我的“SkScene”中演示另一个Sprite kit 从场景中显示另一个视图控制器,sprite-kit,nsnotifications,social-framework,Sprite Kit,Nsnotifications,Social Framework,我正试图从我的“SkScene”中演示另一个viewController。 这是我的主视图控制器(tuViewController) 代码: 这是我的“场景”: 我想展示的viewController是facebook-likeviewdemoviewcontroller,我需要回到“SkScene” 我得到了sigabrt错误,我尝试了几种方法来呈现viewController,但总是失败,有一次我切换到viewController,但它完全是黑色的。我读了很多关于如何做到这一点的书,但我个人
viewController
。
这是我的主视图控制器(tuViewController)
代码:
这是我的“场景”:
我想展示的viewController
是facebook-likeviewdemoviewcontroller
,我需要回到“SkScene”
我得到了sigabrt错误
,我尝试了几种方法来呈现viewController
,但总是失败,有一次我切换到viewController
,但它完全是黑色的。我读了很多关于如何做到这一点的书,但我个人无法理解。我感谢你的帮助
我也尝试了通知中心
主视图控制器
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(goToGameOverViewController:)
name:@"GoToGameOverViewController"
object:nil];
-(void)goToGameOverViewController:(NSNotification *) notification {
FacebookLikeViewDemoViewController *helpVC = [[FacebookLikeViewDemoViewController alloc]initWithNibName:@"HelpViewController" bundle:nil];
UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
[rootVC presentViewController:helpVC animated:YES completion:nil];
}
场景
[[NSNotificationCenter defaultCenter]
postNotificationName:@"GoToGameOverViewController" object:self];
但我也犯了同样的错误。我更愿意弄清楚为什么通知的方式不起作用。根据你的问题,我假设你想在社交媒体上发帖 您可以将视图控制器的引用传递到场景,也可以使用
NSNotificationCenter
。我更喜欢用后者
首先确保已将Social.framework添加到项目中
将社交框架导入视图控制器#导入
然后在视图控制器的viewDidLoad
方法中添加以下代码:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(createTweet:)
name:@"CreateTweet"
object:nil];
NSString *tweetText = @"I just beat the last level.";
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:tweetText forKey:@"tweetText"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"CreateTweet" object:self userInfo:userInfo];
接下来,将此方法添加到视图控制器:
-(void)createTweet:(NSNotification *)notification
{
NSDictionary *tweetData = [notification userInfo];
NSString *tweetText = (NSString *)[tweetData objectForKey:@"tweetText"];
NSLog(@"%@",tweetText);
// build your tweet, facebook, etc...
SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
在场景中的适当位置(赢局、输局等)添加以下代码:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(createTweet:)
name:@"CreateTweet"
object:nil];
NSString *tweetText = @"I just beat the last level.";
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:tweetText forKey:@"tweetText"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"CreateTweet" object:self userInfo:userInfo];
上面的代码发送一个带有文本的NSNotification,您的视图控制器将接收并执行指定的方法(在上面的示例中是createTweet)。请看一看:请在继续之前完整阅读Apple文档,它可以在这里找到我尝试使用Notification center Resolution,但也崩溃了..出现了什么异常?当我调用FaceBookLikeViewViewController*helpVC=[[FaceBookLikeViewViewController alloc]initWithNibName:@“FaceBookLikeViewViewController”捆绑包时:nil];[self-presentViewController:helpVC动画:是完成:无];它只是崩溃了。我尝试使用FaceBookLikeViewViewController*helpVC=[[FaceBookLikeViewViewController alloc]init];然后它改变了视图,但完全是黑屏。谢谢,我找到了通知中心的方法,这是最好的方法,但我有另一个问题,在这里描述>