子类化UIWindow [英] Subclassing UIWindow

查看:166
本文介绍了子类化UIWindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是试图子类化UIWindow,以便我可以拦截一些通知。除了下面列出的代码,我还进入MainWindow.xib并更新UIWindow对象到我的子类。它加载好,问题是我的选项卡栏上的选项卡没有反应(在下面的示例中,我只添加了一个选项卡,但在我的应用程序,我有多个(这不是问题))。任何人都可以看到我可能做错了什么?感谢。

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;

@class UISubclassedWindow;

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

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

@end

AppDelegate.m / p>

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;
}


推荐答案

UIWindows - (void)sendEvent:(UIEvent *)事件方法,但是没有调用super。我打电话给它,一切都解决了。

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.

这篇关于子类化UIWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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