I have this weird problem.. I’m building an in-house app that should register all touch events inside the app and, when a touch occurs, reset a timer. The timer checks if the user is inactive for more than 60 seconds and then logs him/her out of the system.
Now… I want to subclass UIWindow and steal all touch-events through there BUT it’s impossible! This is the great tutorial I’m following, (the downloadable sample works) but implemented in my project, the code doesn’t work…
Here is my AppDelegate.h file:
#import <UIKit/UIKit.h>
#import "TouchWindow.h"
@interface StureplansHLMAppDelegate : UIResponder <UIApplicationDelegate> {
TouchWindow *window;
Settings *appSettings;
}
@property (nonatomic, retain) TouchWindow *window;
@property (nonatomic, retain) Settings *appSettings;
@end
And here is the .m file
#import "StureplansHLMAppDelegate.h"
#import "TouchWindow.h"
#import "WelcomeScreen.h"
@implementation StureplansHLMAppDelegate
@synthesize window;
@synthesize appSettings;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[TouchWindow alloc] init];
self.window = [[TouchWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
WelcomeScreen *startScreen = [[WelcomeScreen alloc] init];
[self.window addSubview:startScreen.view];
[self.window makeKeyAndVisible];
return YES;
}
When i instantiate with my custom UIWindow class the app is just black and never loads the view…
I’m using XCode 4.2 iOS 5 and storyboard. Can someone help me? How do I get it to work?
You need to retain startScreen somewhere. Instead of adding startScreen’s view to the window with
addSubview, simply set it as the rootViewController of the window