gpt4 book ai didi

ios - 如何从Appdelegate显示uiviewcontoller

转载 作者:行者123 更新时间:2023-12-01 18:58:58 24 4
gpt4 key购买 nike

我正在使用带有uitabbarcontoller(带有5个uiviewcontrollers)和uinavigation bar的应用程序。
我已经在应用程序中创建了所有这些文件,但是当我运行它时,它不起作用

这是AppDelegate.m类:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UINavigationController *navCon = [[UINavigationController alloc] init];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];

HomePageView *viewController = [[HomePageView alloc] init];
FeedViewController *feedViewController=[[FeedViewController alloc]init];
ProfileViewController *profileViewController=[[ProfileViewController alloc]init];
PlayViewController *playViewController = [[PlayViewController alloc]init];
ListeningSessionViewController *listeningSessionViewController= [[ListeningSessionViewController alloc]init];
RecievedViewController *recievedViewController =[[RecievedViewController alloc]init];

tabBarController.viewControllers=[NSArray arrayWithObjects:feedViewController,profileViewController,playViewController,listeningSessionViewController,recievedViewController, nil];

//navigating to the UITabBarController that you created
[navCon pushViewController:tabBarController animated:YES];
[navCon pushViewController:viewController animated:NO];

return YES;
}

最佳答案

.h

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navC;
@property (strong, nonatomic) UITabBarController *tabC;

中。mappDidFinish
// Initialize window
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];

// Initialize your five tab controllers. with each tab has its own navigation controller
FeedViewController *feedViewController=[[FeedViewController alloc]init];
UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:feedViewController];

ProfileViewController *profileViewController=[[ProfileViewController alloc]init];
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:profileViewController];

PlayViewController *playViewController = [[PlayViewController alloc]init];
UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:playViewController];

ListeningSessionViewController *listeningSessionViewController= [[ListeningSessionViewController alloc]init];
UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:listeningSessionViewController];

RecievedViewController *recievedViewController =[[RecievedViewController alloc]init];
UINavigationController *nav5 = [[UINavigationController alloc]initWithRootViewController:recievedViewController];

// initialize tabbarcontroller and set your viewcontrollers.
self.tabC = [[UITabBarController alloc]init];
self.tabC.viewControllers=[NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nav5, nil];

// Inititalize Navigationcontroller and set root as tabbar.
self.navC = [[UINavigationController alloc]initWithRootViewController:self.tabC];

// Set Window rootview as navigation.
self.window.rootViewController = self.navC;

// Show window
[self.window makeKeyAndVisible];

也许这会对您有所帮助。

关于ios - 如何从Appdelegate显示uiviewcontoller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24212620/

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