我想通过GameOverScene.m中的[self.delegate showShareScreen]
委托我的方法,但我无法委托。我想知道原因并解决它。
工作图像是Game Over Scene中有一个推特图像。当我触摸它时,它将起作用,并且将出现Twitter共享屏幕,我可以使用它。
GameOverScene.h
#import <SpriteKit/SpriteKit.h>
@protocol sceneDelegate <NSObject>
-(void)showShareScreen;
@end
@interface GameOverScene : SKScene
@property (weak, nonatomic) id <sceneDelegate> delegate;
- (id)init;
@end
GameOverScene.m
#import "GameOverScene.h"
#import "NewGameScene.h"
#import "MainScene.h"
#import <Social/Social.h>
@implementation GameOverScene
@synthesize delegate;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];
if([node.name isEqualToString:@"twitterbutton"]){
[self.delegate showShareScreen];
//When I use the breakpoint, it is ignored.**
}
}
ViewController.h
#import <UIKit/UIKit.h>
#import <SpriteKit/SpriteKit.h>
#import <iAd/iAd.h>
#import "GameOverScene.h"
@interface ViewController : UIViewController <sceneDelegate>
@end
ViewController.m
#import "ViewController.h"
#import "NewGameScene.h"
#import <Social/Social.h>
#import "GameOverScene.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)loadView
{
self.view = [[SKView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
GameOverScene *theScene = [[GameOverScene alloc]init];
theScene.delegate = self;
}
-(void)showShareScreen
{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:@"TestTweet from the Game !!"];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
}
@end