子视图中的触摸调用超级视图的方法



我有两个类,BoxNinjaViewController (Xcode创建的默认视图)和GameClass。GameClass作为子视图加载,如下所示:

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

GameClass视图看起来很正常,但当我尝试添加touchesBegan:方法时,它的行为很有趣。

在BoxNinjaViewController

。m,我有:

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

和GameClass。m,我有:

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

…当我点击GameClass的视图时,它会NSLogs

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

关于发生了什么,我该如何解决它有什么想法吗?

不知何故,使game对象成为BoxNinjaViewController的属性来修复它。我猜它阻止了自动释放还是怎么的?

最新更新