iphone - 子类化 UIWindow

标签 iphone objective-c ios cocoa-touch uiviewcontroller

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

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

最佳答案

问题是我包含了 UIWindows - (void)sendEvent:(UIEvent *)event 方法,但没有在其上调用 super。我在上面调用了 super,一切都已修复。

关于iphone - 子类化 UIWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8844552/

相关文章:

iphone - 如何解决这种循环依赖?

objective-c - 在 iOS 中使用相对位置布局 View 的最佳方式?

iphone - iPhone OS 3.0录音报错kAudioQueueErr_CannotStart

iOS - 无法在按钮上设置文本

ios - 添加第二个证书时,SecItemAdd 返回 -25299

objective-c - 如何使用 libldap 跟踪别名?

iphone - 嵌套树结构中的核心数据获取请求

ios - AFNetworking 2.0 是否支持后台任务? - IOS 7

ios - IAP iOS Objective c 中的 SKErrorDomain Code=0 "Cannot connect to iTunes Store"

ios - 我如何知道哪些联系人有 iMessage?