开发者

Programmatically created window appears but doesn't respond to touch events

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");

开发者_运维百科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];

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?


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


You may try to modify the fourth parameter from "nil" to the application delegate name in main.c

For example Modify UIApplicationMain(argc, argv, nil, nil) to UIApplicationMain(argc, argv, nil, @"HelloWorldAppDelegate")


I had a similar problem and what helped me was adding

[window setRootViewController:tabBarController];

...I had only been adding the view instead of the whole view controller.


I had a similar problem when removing the mainwindow.xib and creating the window programmatically: I still had that line:

[self.window addSubview:rootcontroller.view];

Removing it solved the problem.


For me, I had to use:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

Rather than:

self.window = [[UIWindow alloc] init];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜