ios - 如何从Appdelegate显示uiviewcontoller

标签 ios objective-c uinavigationcontroller uitabbarcontroller appdelegate

我正在使用带有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/

相关文章:

ios - 用 Swift 编写 Cordova/Ionic 插件

ios - Mixpanel nameTag 不工作 iOS

objective-c - 在 Cocoa 应用程序中运行 ssh-askpass

ios - 以编程方式创建和显示 UIBarButtonItem 的正确方法是什么?

ios - 在两个 UINavigationController 之间切换

iphone - 解析 XML 内部 XML 标签 Objective-C

ios - 右图像按钮从右侧对齐 x 点

ios - 根据 NSDictionaries 的 NSArray 内的值创建 UITableView 的索引

objective-c - NSOutlineView:拖动项目时避免出现黄色边框?

iphone - 为什么 popViewController 每隔一段时间才起作用