Ios 警告:尝试使用SLComposeViewController在其视图不在窗口层次结构中的*上显示*
当我在游戏中推推推推推推特图像时,我想显示共享图像(SLComposeViewController的模式显示)。Ios 警告:尝试使用SLComposeViewController在其视图不在窗口层次结构中的*上显示*,ios,objective-c,delegates,sprite-kit,hierarchy,Ios,Objective C,Delegates,Sprite Kit,Hierarchy,当我在游戏中推推推推推推特图像时,我想显示共享图像(SLComposeViewController的模式显示)。 但是,当我按下推特按钮时,屏幕不会显示,日志会显示标题。 然后,我搜索了类似的问题,但我不知道该怎么办。。。 我知道,[ViewDidLoad]和[ViewDidAppear]很重要。 下面是我的代码 ViewController.m #import "ViewController.h" #import "NewGameScene.h" #import <Social/Soci
但是,当我按下推特按钮时,屏幕不会显示,日志会显示标题。
然后,我搜索了类似的问题,但我不知道该怎么办。。。 我知道,[ViewDidLoad]和[ViewDidAppear]很重要。 下面是我的代码 ViewController.m
#import "ViewController.h"
#import "NewGameScene.h"
#import <Social/Social.h>
#import "GameOverScene.h"
@interface ViewController ()
{
GameOverScene *gameOver;
}
@end
@implementation ViewController
//Loads the view onto our main class
- (void)loadView
{
self.view = [[SKView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
}
//Executes when view finishes loading
- (void)viewWillLayoutSubviews
{
//extracted important code.
[super viewDidLoad];
gameOver = [[GameOverScene alloc]init];
gameOver.delegate = self;
}
-(void)showShareScreen
{
NSLog(@"showShareScreen");
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
poseViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:@"TestTweet from the Game !!"];
NSLog(@"self = %@",self);
[self presentViewController:tweetSheet animated:YES completion:nil];
}
else {
NSLog(@"not sls type twitter");
}
}
@end
GameOverScene.m
#import "GameOverScene.h"
#import "NewGameScene.h"
#import "MainScene.h"
#import <Social/Social.h>
//Screen is touched
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//Same as in NewGameScene menu
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];
//Is the retry button touched?
if([node.name isEqualToString:@"twitterbutton"]){
NSLog(@"self.delegate = %@",self.delegate);
[self.delegate showShareScreen];
if (nil == self.delegate) NSLog(@"delegate is nil");
}
}
@end
#导入“GameOverScene.h”
#导入“NewGameSecene.h”
#导入“mainsecene.h”
#进口
//触摸屏幕
-(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件
{
//与新游戏场景菜单中的相同
UITouch*touch=[触摸任何对象];
CGPoint位置=[触摸位置Innode:self];
SKNode*node=[自身节点点:位置];
//是否触按了重试按钮?
if([node.name isEqualToString:@“twitterbutton”]){
NSLog(@“self.delegate=%@”,self.delegate);
[self.delegate showShareScreen];
如果(nil==self.delegate)NSLog(@“delegate为nil”);
}
}
@结束
下面的注释中描述了该问题
GameOverScene *gameOver = [[GameOverScene alloc] initWithSize:self.size];
ViewController *vc = [[ViewController alloc] init];//This is causing the problem.
//The delegate has to be the viewController which is presenting the scene
gameOver.delegate = vc;
NSLog(@"vc = %@",vc);
[gameOver didMoveToView:self.view]; //Why are you calling this line??
//Present the game over scene with the fade in transition
[self.scene.view presentScene:gameOver transition:transition];
而不是行:
gameOver.delegate = vc;
请尝试使用以下行:
gameOver.delegate = self.view.window.rootViewController;
编辑:
使用线路
gameOver.delegate = (ViewController*) self.view.window.rootViewController;
应删除警告下面的注释中描述了问题
GameOverScene *gameOver = [[GameOverScene alloc] initWithSize:self.size];
ViewController *vc = [[ViewController alloc] init];//This is causing the problem.
//The delegate has to be the viewController which is presenting the scene
gameOver.delegate = vc;
NSLog(@"vc = %@",vc);
[gameOver didMoveToView:self.view]; //Why are you calling this line??
//Present the game over scene with the fade in transition
[self.scene.view presentScene:gameOver transition:transition];
而不是行:
gameOver.delegate = vc;
请尝试使用以下行:
gameOver.delegate = self.view.window.rootViewController;
编辑:
使用线路
gameOver.delegate = (ViewController*) self.view.window.rootViewController;
应删除警告下面的注释中描述了问题
GameOverScene *gameOver = [[GameOverScene alloc] initWithSize:self.size];
ViewController *vc = [[ViewController alloc] init];//This is causing the problem.
//The delegate has to be the viewController which is presenting the scene
gameOver.delegate = vc;
NSLog(@"vc = %@",vc);
[gameOver didMoveToView:self.view]; //Why are you calling this line??
//Present the game over scene with the fade in transition
[self.scene.view presentScene:gameOver transition:transition];
而不是行:
gameOver.delegate = vc;
请尝试使用以下行:
gameOver.delegate = self.view.window.rootViewController;
编辑:
使用线路
gameOver.delegate = (ViewController*) self.view.window.rootViewController;
应删除警告下面的注释中描述了问题
GameOverScene *gameOver = [[GameOverScene alloc] initWithSize:self.size];
ViewController *vc = [[ViewController alloc] init];//This is causing the problem.
//The delegate has to be the viewController which is presenting the scene
gameOver.delegate = vc;
NSLog(@"vc = %@",vc);
[gameOver didMoveToView:self.view]; //Why are you calling this line??
//Present the game over scene with the fade in transition
[self.scene.view presentScene:gameOver transition:transition];
而不是行:
gameOver.delegate = vc;
请尝试使用以下行:
gameOver.delegate = self.view.window.rootViewController;
编辑:
使用线路
gameOver.delegate = (ViewController*) self.view.window.rootViewController;
应删除警告错误是显示的视图控制器(
viewcontroller
)当前不可见,因此无法显示其他视图控制器。模态需要从可见视图控制器显示;tweetSheet.modalTransitionStyle=UIModalTransitionStyleCoverVertical;但问题没有解决…错误是显示的viewcontroller(viewcontroller
)当前不可见,因此无法显示其他视图控制器。模态需要从可见视图控制器显示;tweetSheet.modalTransitionStyle=UIModalTransitionStyleCoverVertical;但问题没有解决…错误是显示的viewcontroller(viewcontroller
)当前不可见,因此无法显示其他视图控制器。模态需要从可见视图控制器显示;tweetSheet.modalTransitionStyle=UIModalTransitionStyleCoverVertical;但问题没有解决…错误是显示的viewcontroller(viewcontroller
)当前不可见,因此无法显示其他视图控制器。模态需要从可见视图控制器显示;tweetSheet.modalTransitionStyle=UIModalTransitionStyleCoverVertical;但它还没有解决…非常感谢你!!我终于明白了。谢谢你。但是,行中有一个选项“从不兼容的类型“UIViewController”分配给“id”。请问你知道原因吗? 还有,我可以问一下如何增加你的声誉吗?如果这个答案适合你,只要点击旁边的勾号就可以了。另外,投票也会有帮助。我会检查和研究它,非常感谢你教会我一切!!非常感谢你!!我终于明白了。谢谢你。但是,行中有一个选项“从不兼容的类型“UIViewController”分配给“id”。请问你知道原因吗? 还有,我可以问一下如何增加你的声誉吗?如果这个答案适合你,只要点击旁边的勾号就可以了。另外,投票也会有帮助。我会检查和研究它,非常感谢你教会我一切!!非常感谢你!!我终于明白了。谢谢你。但是,行中有一个选项“从不兼容的类型“UIViewController”分配给“id”。请问你知道原因吗? 还有,我可以问一下如何增加你的声誉吗?如果这个答案适合你,只要点击旁边的勾号就可以了。另外,投票也会有帮助。我会检查和研究它,非常感谢你教会我一切!!非常感谢你!!我终于明白了。谢谢你。但是,行中有一个选项“从不兼容的类型“UIViewController”分配给“id”。请问你知道原因吗? 还有,我可以问一下如何增加你的声誉吗?如果这个答案适合你,只要点击旁边的勾号就可以了。另外,投票也会有帮助。我会检查和研究它,非常感谢你教会我一切!!