警告:尝试显示其视图不在窗口层次结构中的* on *

时间:2014-03-14 14:08:22

标签: ios objective-c cocoa-touch

我是目标C的新手,我试图在我的游戏中为twitter创建一个分享按钮。我使用spritebuilder来创建我的所有按钮和精灵。我的所有代码都在MainScene.m中,而我的twitter共享表代码在ShareViewController.m中

在我的MainScene.m文件中,我有一个方法sendToController,它使用shareViewController的对象调用ShareToTwitter中的方法,该方法位于ShareViewController.m中。由于某种原因,这个推文不是可见的,而且我收集的是有一个窗口heirachy问题,我无法解决。

以下是MainScene.m中的代码

ShareViewController *_shareViewController;

@synthesize shareViewController;

(void)sendToController {
_shareViewController = [ShareViewController alloc];
[_shareViewController postToTwitter];
}

以下是ShareViewController.m的代码

@implementation ShareViewController {

MainScene *_mainSceneObj;
}

- (void)viewDidLoad
{
[super viewDidLoad];
_mainSceneObj.ShareViewController = self;
}

- (void)postToTwitter {

NSLog(@"in postToTwitter %d", [SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]);
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{

    SLComposeViewController *tweetSheet = [SLComposeViewController
                                           composeViewControllerForServiceType:SLServiceTypeTwitter];

    // Sets the completion handler.  Note that we don't know which thread the
    // block will be called on, so we need to ensure that any required UI
    // updates occur on the main queue
    tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {
        switch(result) {
                //  This means the user cancelled without sending the Tweet
            case SLComposeViewControllerResultCancelled:
                break;
                //  This means the user hit 'Send'
            case SLComposeViewControllerResultDone:
                break;
        }
    };

    //  Set the initial body of the Tweet
    [tweetSheet setInitialText:@"just setting up my twttr"];

    if (![tweetSheet addImage:[UIImage imageNamed:@"screen.png"]]) {
        NSLog(@"Unable to add the image!");
    }

    if (![tweetSheet addURL:[NSURL URLWithString:@"http://twitter.com/"]]){
        NSLog(@"Unable to add the URL!");
    }

    //  Presents the Tweet Sheet to the user
    [self presentViewController:tweetSheet animated:NO completion:^{
        NSLog(@"Tweet sheet has been presented.");
    }];    }

}

0 个答案:

没有答案