Hi,
I created a very very basic iPhone app with File/New Projet/View-Based application. No NIB file there.
Here is my appDelegate
.h
@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
MyViewController *viewController;
}
.m
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
And here is my loadView method in my controller
- (void)loadView {
CGRect mainFrame = [[UIScreen mainScreen] applicationFrame];
UIView *contentView = [[UIView alloc] initWithFrame:mainFrame];
contentView.backgroundColor = [UIColor redColor];
self.view = contentView;
[contentView release];
}
Now, in order to catch the touchesBegan event, I created a new subclass of UIView:
.h
@interface TouchView : UIView {
}
.m
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"Touch detected");
}
and modified the second line in my loadView into this :
TouchView *contentView = [[UIView alloc] initWithFrame:mainFrame];
Why is touchesBegan never called?