iphone以编程方式初始化选项卡栏控制器视图
我想以编程方式初始化我的选项卡栏控制器,但我只得到一个带有代码的空白屏幕。我试着模仿,一行一行地模仿,但显然有些地方出了问题。有什么建议吗 总的来说,m:iphone以编程方式初始化选项卡栏控制器视图,iphone,uitabbarcontroller,Iphone,Uitabbarcontroller,我想以编程方式初始化我的选项卡栏控制器,但我只得到一个带有代码的空白屏幕。我试着模仿,一行一行地模仿,但显然有些地方出了问题。有什么建议吗 总的来说,m: #import <UIKit/UIKit.h> int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc,
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"DubbleWrapAppDelegate");
[pool release];
return retVal;
}
plist设置为没有被引用的NIB文件。您应该保留窗口对象。您将其标记为自动释放,因此它将在下一个应用程序循环中释放 不要在窗口上调用自动释放:
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
啊。添加self.window=window不起作用(可能我把它放错了位置),但是删除自动释放消息(因为我在dealloc函数中释放了它)起作用。谢谢
@implementation DubbleWrapAppDelegate
@synthesize window;
@synthesize tabBarController;
- init {
if (self = [super init]){
// initialize to nil
window = nil;
tabBarController = nil;
}
return self;
}
- (void)applicationDidFinishLaunching:(UIApplication *)application {
SafeTableViewController *vc1 = [[SafeTableViewController alloc] initWithStyle:UITableViewStylePlain];
[vc1 setSafeItems:[SafeItem knownSafeItems]]; // Set the list of known SafeItems:
UINavigationController *nc1;
nc1 = [[UINavigationController alloc] initWithRootViewController:vc1];
[vc1 release];
BoxXRayTableViewController *vc2 = [[BoxXRayTableViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *nc2;
nc2 = [[UINavigationController alloc] initWithRootViewController:vc2];
[vc2 release];
AboutLibertyViewController *vc3 = [[AboutLibertyViewController alloc] init];
UINavigationController *nc3;
nc3 = [[UINavigationController alloc] initWithRootViewController:vc3];
[vc3 release];
NSArray* controllers = [NSArray arrayWithObjects:nc1, nc2, nc3, nil];
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = controllers;
[controllers release];
// Add the tab bar controller's current view as a subview of the window
window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[window setBackgroundColor:[UIColor redColor]];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
[nc1 release];
[nc2 release];
[nc3 release];
}
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];