I'm just trying to subclass UIWindow to catch some notifications. Along with the code below, I also go to MainWindow.xib and update the UIWindow object for my subclass. It loads normally, the problem is that the tabs on the tab bar do not respond (in the example below I added only one tab, but in my application I have several (this is not a problem)). Can anyone see what I can do wrong? Thanks.
UISubclassedWindow.h
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
import
@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; }
source share