New to iPhone SDK: touchesBegan not called

Posted by coriolan on Stack Overflow See other posts from Stack Overflow or by coriolan
Published on 2009-10-26T00:05:56Z Indexed on 2010/05/24 3:31 UTC
Read the original article Hit count: 915

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?

© Stack Overflow or respective owner

Related posts about iphone-sdk-3.0

Related posts about uiview