gpt4 book ai didi

iphone - 在 iPhone 应用程序中使用 tabBar 时出现黑屏

转载 作者:行者123 更新时间:2023-12-03 19:54:39 27 4
gpt4 key购买 nike

我正在我的 iPhone 应用程序中添加 UITabBarController。我在 TabsAppDelegate.h 中提到过它,如下所示

#import <UIKit/UIKit.h>

@interface TabsAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;


@end

和我的 TabsAppDelegate.m didFinishLaunchingWithOptions 方法

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions {    



// Add the tab bar controller's view to the window and display.
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];

return YES;
}

现在,在 MainWindow.xib 中,我添加了选项卡栏 Controller 并与 tabBarController 建立连接。后来我创建了 FirstViewController 和 SeconViewController 这是两个 ViewController。现在,在第一个选项卡上,我添加了 FirstViewController.xib,在第二个选项卡上,我使用构建器界面添加了 SecondViewController.xib 文件。

但是当我运行该项目时它显示黑屏。需要你的帮助。提前致谢。

最佳答案

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{


UIViewController *viewController1 = [[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil] autorelease];
UINavigationController *navviewController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
navviewController1.title = @"FirstTitle";
// navviewController1.navigationBarHidden=YES;

UIViewController *viewController2 = [[[yourviewController2 alloc] initWithNibName:@"yourviewController2" bundle:nil] autorelease];
UINavigationController *navviewController2=[[UINavigationController alloc]initWithRootViewController:viewController2];
// navviewController2.navigationBarHidden=YES;
navviewController2.title = @"SecondTitle";

UIViewController *viewController3 = [[[yourviewController3 alloc] initWithNibName:@"yourviewController2" bundle:nil] autorelease];
UINavigationController *navviewController3=[[UINavigationController alloc]initWithRootViewController:viewController3];
// navviewController3.navigationBarHidden=YES;
navviewController3.title = @"ThirdTitle";

//..... and so on depend on your requirement

self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navviewController1, navviewController2 , navviewController3 ,nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
}

试试这个,你只是忘记添加 rootViewController

关于iphone - 在 iPhone 应用程序中使用 tabBar 时出现黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12951091/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com