iPhone 中没有 UIView 或 UIViewController 的情况下会调用 TouchBegan 方法吗?
我创建了一个应用程序,其中只有 appdelegate 类。我不创建 UIView 或视图控制器。我刚刚在窗口中添加了文本字段、标签和按钮。
我想当用户点击文本框时隐藏键盘。这通常是通过 TouchBegan 方法来实现的。为了实现这个方法,我们需要做两件事。
一种是在头文件(.h)中添加,
另一种是设置textField的委托。那就是,textField.delegate=self;
我做了这两件事。但touchesBegan方法仍然没有被调用。
为什么?我应该有一个 UIView 或 UIViewController 类吗?
提前致谢
I created an app in where i have appdelegate class only. I dont create a UIView or a view controller. I just added textFields, labels and buttons in my window.
I want to hide the keyboard when the user taps out of the text boxes. This is normally achieved by the method touchesBegan. For implementing this method, two things we need to do.
One is add in the header file(.h)
Another one is set the textField's delegate. Thats is, textField.delegate=self;
I did those two things. But still the touchesBegan method did not called.
Why? Should i have a UIView or UIViewController class for it?
Thanks in Advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
UIWindow
是UIView
的子类,因此您可以直接连接到它们。但这是一个非常糟糕的设计模式。考虑修改您的应用程序,使其使用单个视图控制器,而不是在应用程序委托中执行所有操作。否则,您就会临时操纵应用程序委托去做它从未设计过的事情。UIWindow
is a subclass ofUIView
, so you could just hook into those. But this is a seriously bad design pattern. Consider modifying your application so it uses a single view controller, rather than doing everything in the app delegate. Otherwise you're jury-rigging the app delegate to be something it was never designed to do.touchesBegan 是一个 UIView 方法。如果你想在你的设置中执行此操作,你应该创建一个 UIView 子类,将所有控件放入该子类中,并在 UIView 子类中实现touchesBegan。
touchesBegan is a UIView method. if you want to do it in your setup you should create a UIView subclass, put all your controls in that one and implement touchesBegan in the UIView subclass.