我只是试图子类UIWindow,以便我可以拦截一些通知。随着下面列出的代码,我也进入MainWindow.xib并更新UIWindow对象到我的子类。它加载正常,问题是我的标签栏上的选项卡没有响应(在下面的例子中,我只添加了一个选项卡,但在我的应用程序中我有多个(这不是问题))。任何人都可以看到我可能做错了什么?谢谢。子类化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;
}
也许是个愚蠢的问题,但是你在xib中设置了主窗口的类吗? – mvds 2012-01-13 01:10:50
但你为什么要这样?如果你放置正确的自动识别模板,那么你的视图将会与不断变化的导航栏完美对齐。有一个合理的原因是它在景观上略微缩小。 – mvds 2012-01-13 01:14:02
@mvds - 对你的第一个评论,根本不是一个愚蠢的问题,因为它是正确的。现在我已经将窗口设置为mainwindow.xib中的子类(并且还将关键字outlet添加到了属性中),并且当它加载它时会激发我的NSLog消息,但现在应用程序被冻结。 – 2012-01-13 01:18:50