gpt4 book ai didi

objective-c - touchesBegan 在 uiresponder 的子类中被忽略

转载 作者:行者123 更新时间:2023-11-28 17:38:40 25 4
gpt4 key购买 nike

使用 objective-c 开发 ios 应用程序并使用 xcode。我有一个继承自另一个类的类,该类继承自 UIResponder,它包含一个 View 。我在子类中有一个 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(一种常用模式)的情况下覆盖此方法,则还必须覆盖其他处理触摸事件的方法,如果仅作为 stub (空)实现。”所以我在所有其他触摸事件中 stub ,但发布版本没有变化

最佳答案

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

UIViewController 在响应链中的位置在它的 View 和 View 的父 View 之间,所以为了获得相同的行为,你需要在你的两个 View 中覆盖 nextResponder View 和管理它的 Controller 。 View 应返回 Controller , Controller 应返回 View 的父 View 。

关于objective-c - touchesBegan 在 uiresponder 的子类中被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9017705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com