我只是想继承 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/