出现编程式创建的窗口,但不响应触摸事件 [英] Programmatically created window appears but doesn't respond to touch events

查看:121
本文介绍了出现编程式创建的窗口,但不响应触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建没有MainWindow nib的应用程序,在更新到新的SDK后,我的应用程序完全崩溃了。在main.m的main()函数中有:

I'm creating my app without the MainWindow nib, and after updating to the new SDK, my app completely broke. In the main() function of main.m I have:

int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");

这里是应用程序的相关位:didFinishLaunchingWithOptions:在AppDelegate.m

Here's the relevant bits of application:didFinishLaunchingWithOptions: in AppDelegate.m

window = [[UIWindow alloc] init];

tabBarController = [[UITabBarController alloc] init];

UINavigationController *nav = ...;
UITableViewController *table = ...;

tabBarController.viewControllers = [NSArray arrayWithObjects:nav, table, nil];

[window addSubview:tabBarController.view];
[window makeKeyAndVisible];

当应用程序启动时,标签栏是可见的,第一个选项卡中的视图也是可见的。但是,所有触摸事件都未注册或未传递到窗口本身。我子类化UIWindow并将 window 设置为它的一个实例。在这个子类中,我覆盖了sendEvent:方法,以便在调用它时记录到控制台。没有显示。我做错了什么?

When the app launches, the tab bar is visible and so is the view in the first tab. However, all touch events are either not being registered or not being passed to the window itself. I subclassed UIWindow and set window to be an instance of it. In this subclass, I overrode the sendEvent: method to log to the console whenever it was called. Nothing is showing up. What am I doing wrong?

推荐答案

好吧,我想出来了。希望这有助于某人。这些是我的应用程序中的第一对夫妇:didFinishLaunchingWithOptions:方法:

Well, I figured it out. Hope this helps someone. These are the first couple lines in my application:didFinishLaunchingWithOptions: method:

window = [[UIWindow alloc] init];
window.screen = [UIScreen mainScreen]; // this fixes the problem

这篇关于出现编程式创建的窗口,但不响应触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆