【问题标题】:Touches in subview calling superview's method在调用superview的方法的子视图中进行触摸
【发布时间】:2013-05-26 19:01:20
【问题描述】:

我有两个类,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

关于发生了什么以及如何解决它的任何想法?这就是我设置我以前所有应用程序的方式,我从来没有遇到过这个问题。

【问题讨论】:

    标签: ios objective-c uiview touchesbegan touches


    【解决方案1】:

    不知何故,使game 对象成为BoxNinjaViewController 的属性修复了它。我猜它阻止了它被自动发布或其他什么?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多