Methods in Customized View did not get invoke in AppDelegate, Why?
Posted
by
NorthKyut
on Stack Overflow
See other posts from Stack Overflow
or by NorthKyut
Published on 2011-01-14T11:49:34Z
Indexed on
2011/01/14
11:53 UTC
Read the original article
Hit count: 153
I want the methods pauseGame in customized UIView - MyGameView get invoked when the phone is locked or interrupted. So I have a pauseGame method but it can't stop the timer when user lock screen (command+L). The lock screen did appear but the game still running at the background. So I added the testPause method to MyGameView and MyGameAppDelegate and and put a breakpoint to debug it. When screen locked it, the screen lock appeared and the code did stop at the breakpoint. But when I tried to step into the testPause method, it didn't take me to the method in MyGameView (it just passed it, not skipped) and no message was printed on terminal by NSLog. Why? What did I miss?
//
// MyGameAppDelegate.h
// MyGame
//#import <UIKit/UIKit.h>
@class MyGameViewController;
@class MyGameView;@interface MyGameAppDelegate : NSObject {
UIWindow *window;
MyGameViewController *viewController;
MyGameView *view;
}@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet MyGameViewController *viewController;
@property (nonatomic, retain) IBOutlet MyGameView *view;
@end
//
// MyGameAppDelegate.m
// MyGame
//
#import "MyGameAppDelegate.h"
#import "MyGameViewController.h"
#import "MyGameView.h"
@implementation MyGameAppDelegate
@synthesize window;
@synthesize viewController;
@synthesize view;
- (void)applicationWillResignActive:(UIApplication *)application {
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. */
[view pauseGame];
[view testPause];
}
@end
//
// MyGameView.h
// MyGame@interface MyGameView : UIView {
- (void)pauseGame;
- (void)testPause;
@end
//
// MyGameView.m
// MyGame
//#import "MyGameView.h"
#import "AtlasSprite.h"
#import "MyGameViewController.h"
#import "SecondViewController.h"
@implementation MyGameView
- (void)pauseGame {
[theTimer invalidate];
theTimer = nil;
}
- (void)testPause{
NSLog(@"TestPause");
}
@end
© Stack Overflow or respective owner