【发布时间】:2021-09-04 20:54:20
【问题描述】:
我跟随Programmatically creating tab bar for ViewController 和How can I create a tab view programmatically on iOS 尝试使用objective c 在我的ViewController 中以编程方式创建一个标签栏,但是我的标签栏没有出现。这是我在 AppDelegate.m 中的代码:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[FIRApp configure];
self.ref = [[FIRDatabase database] reference];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
ViewController *viewController = [[ViewController alloc]init];
viewController.title =@"Home";
UINavigationController *nav =[[UINavigationController alloc]initWithRootViewController:viewController];
NSArray *viewControllers = [NSArray arrayWithObjects:viewController, nil];
[viewController release];
[tabBarController setViewControllers:viewControllers animated:NO];
// Put the tabBarController's view on the window.
[self.window addSubview:[tabBarController view]];
self.window.rootViewController = tabBarController;
return YES;
}
没有错误,只是标签栏不显示
【问题讨论】:
-
只需删除这些代码:[viewController release] 和 [self.window addSubview:[tabBarController view]]
-
我已经尝试了您的建议,但仍然没有出现。但是我将相同的代码放入 SceneDelegate.m 并出现了,所以可能是由于我使用的是较新的 Xcode 版本?
标签: objective-c uitabbarcontroller