1

使用目标 c 并使用 xcode 开发 ios 应用程序。我有一个类继承自另一个继承自 UIResponder 的类,它包含一个视图。我在子类中有一个 touchesBegan,但只有在调试/开发模式下运行应用程序时才会调用该事件。当我进行生产/发布构建时,不会调用触摸事件。

// Basic viewcontroller protocol
@protocol SubViewController
    - (void)viewDidAppear:(BOOL)animated;
    - (void)viewDidDisappear:(BOOL)animated;
    - (void)viewWillAppear:(BOOL)animated;
    - (void)viewWillDisappear:(BOOL)animated;
    - (void)viewDidLoad;
    -(UIView *)view;
@end


@interface SubViewController : UIResponder<SubViewController> {
}

/////////////////////////////////////////////////////////////////////////////////


// A custom subview controller
//

@interface mySubViewController : SubViewController {

}

在 mysubviewcontroller 类中我有

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   //some code and magic
}

现在正如我所说,在调试中运行它很好,但在发布中忽略了触摸事件。请说任何有助于澄清这一点的提示、想法或问题。提前致谢

编辑:我在文档中看到了这一点“如果您在不调用 super 的情况下覆盖此方法(一种常见的使用模式),您还必须覆盖处理触摸事件的其他方法,如果只是作为存根(empy)实现。” 所以我在所有其他触摸事件中存根,但发布版本没有变化

4

1 回答 1

0

由于您没有子类UIViewController化(它会自动执行此操作),因此您需要手动将响应者添加到响应者链中。

AUIViewController在响应者链中的位置位于其视图和视图的父视图之间,因此要获得相同的行为,您需要nextResponder在视图和管理它的控制器中覆盖。视图应该返回控制器,控制器应该返回视图的超级视图。

于 2012-01-26T13:49:03.390 回答