[英]Touches in subview calling superview's method
I have two classes, BoxNinjaViewController
(the default view created by Xcode) and GameClass
. 我有两个类, BoxNinjaViewController
(由Xcode创建的默认视图)和GameClass
。 GameClass is loaded as a subview, like so: GameClass作为子视图加载,如下所示:
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. GameClass视图看起来像普通的一样,但是当我尝试添加touchesBegan:
方法时,它的表现很有趣。
In BoxNinjaViewController.m, I have: 在BoxNinjaViewController.m中,我有:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"sauce");
}
and in GameClass.m, I have: 在GameClass.m中,我有:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"tuna");
}
...and when I click in GameClass's view, it NSLogs ...当我在GameClass的视图中单击时,它是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. 不知何故,使game
对象成为BoxNinjaViewController
的属性BoxNinjaViewController
修复。 I guess it stopped it from being autoreleased or something? 我猜它阻止了它的自动发布?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.