简体   繁体   中英

Touches in subview calling superview's method

I have two classes, BoxNinjaViewController (the default view created by Xcode) and GameClass . GameClass is loaded as a subview, like so:

GameClass *game = [[GameClass alloc] initWithNibName:@"GameClass" bundle:nil];
[self.view addSubview: game.view];

The GameClass view appears like normal, but when I try to add the touchesBegan: method, it acts funny.

In BoxNinjaViewController.m, I have:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    NSLog(@"sauce");
}

and in GameClass.m, I have:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    NSLog(@"tuna");
}

...and when I click in GameClass's view, it NSLogs

2013-05-26 14:54:24.908 BoxNinja[75023:c07] sauce

Any Ideas on what's going on, and how I could fix it? This his how I've set up all my previous apps, and I've never had this issue.

Somehow, making the game object a property of BoxNinjaViewController fixed it. I guess it stopped it from being autoreleased or something?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM