I am simply trying to subclass UIWindow so that I can intercept some notifications. Along with the code listed below I also go into MainWindow.xib and update the UIWindow object to my sub class. It loads up fine, problem is the tabs on my tab bar are unresponsive (in the example below I only added one tab, but in my app I have multiple (that's not the problem)). Can anyone see what I might be doing wrong? Thanks.
UISubclassedWindow.h
#import <UIKit/UIKit.h>
@interface UISubclassedWindow : UIWindow
{
}
@end
UISubclassedWindow.m
#import "UISubclassedWindow.h"
@implementation UISubclassedWindow
- (id) initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
NSLog(@"init");
}
return self;
}
- (void)makeKeyAndVisible
{
[super makeKeyAndVisible];
NSLog(@"makeKeyAndVisible");
}
- (void)becomeKeyWindow
{
[super becomeKeyWindow];
NSLog(@"becomeKeyWindow");
}
- (void)makeKeyWindow
{
[super makeKeyWindow];
NSLog(@"makekeyWindow");
}
- (void)sendEvent:(UIEvent *)event
{
}
- (void)dealloc
{
[super dealloc];
}
@end
AppDelegate.h
@class UISubclassedWindow;
@interface My_AppAppDelegate : NSObject <UIApplicationDelegate>
{
UISubclassedWindow *window;
}
@property (nonatomic, retain) IBOutlet UISubclassedWindow *window;
@end
AppDelegate.m
@synthesize window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UITabBarController *tabBarController = [[UITabBarController alloc] init];
MainViewController *mainViewController = [[MainViewController alloc] initWithViewType: 0];
UINavigationController *mainNavigationController = [[UINavigationController alloc] initWithRootViewController: mainViewController];
mainNavigationController.title = @"Main";
[[mainNavigationController navigationBar] setBarStyle: UIBarStyleBlack];
[tabBarController setViewControllers: [NSArray arrayWithObjects: mainNavigationController, nil]];
[self.window setRootViewController: tabBarController];
[self.window makeKeyAndVisible];
[mainViewController release];
[mainNavigationController release];
[tabBarController release];
return YES;
}
The backdrop for your app's user interface and the object that dispatches events to your views.
Yes, you can have multiple windows. A key window is the one who receives the user input.
An object that represents one instance of your app's user interface.
This is a convenience method to show the current window and position it in front of all other windows at the same level or lower. If you only want to show the window, change its isHidden property to false .
The problem was I was including the UIWindows - (void)sendEvent:(UIEvent *)event method, but wasn't calling super on it. I called super on it and everything was fixed.
edit: note that this answers the original question, before a major rewrite changing the entire issue
You should first find out whether there is a documented way (some call, or an overridden method) to change the height of the nav bar. I highly doubt there is one. And I also doubt if UIWindow
is the place to look for it - the nav bar is part of the UINavigationController.
Assuming there is no legal way to force the height to remain 44px, you can try several things:
-shouldAutoRotate.. { return NO; }
. As a quick check, see what happens if you would simply set the frame of the topmost VC to CGRectMake(0,0,480,320);
(either from your subclassed UINavigationController or from the subclassed UIWindow). If everything still works OK, then you only need to add the autorotation part.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With