I want to delegate my method through [self.delegate showShareScreen]
in GameOverScene.m, but I can't delegate that. I would like to know the reason why and solve it.
Working image is that there is a twitter image in Game Over Scene. When I touch it, it will work and twitter share screen will appear and I can use it.
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