子类化UIWindow

Ser*_*nce 5 iphone cocoa-touch objective-c uiviewcontroller ios

我只是试图将UIWindow子类化,以便可以拦截一些通知。除了下面列出的代码,我还进入MainWindow.xib并将UIWindow对象更新为我的子类。它可以很好地加载,问题是我的标签栏上的标签没有响应(在下面的示例中,我仅添加了一个标签,但是在我的应用中,我有多个标签(不是问题))。谁能看到我可能做错了什么?谢谢。

UISubclassedWindow.h

#import <UIKit/UIKit.h>

@interface UISubclassedWindow : UIWindow 
{

}

@end
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

AppDelegate.h

进口

@class UISubclassedWindow;

@interface My_AppAppDelegate : NSObject <UIApplicationDelegate> 
{
    UISubclassedWindow *window;
}

@property (nonatomic, retain) IBOutlet UISubclassedWindow *window;

@end
Run Code Online (Sandbox Code Playgroud)

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;
}
Run Code Online (Sandbox Code Playgroud)

Ser*_*nce 4

问题是我包含了 UIWindows - (void)sendEvent:(UIEvent *)event 方法,但没有调用 super 。我打电话给超级,一切都修好了。