ios - iOS7注册或登录后如何显示标签栏

标签 ios objective-c uinavigationcontroller uitabbarcontroller

基本上,我有一个基于选项卡的应用程序,它需要先从登录页面登录/注册,然后才能看到选项卡栏,我已经在这个问题上花费了大约 3 个小时,但还没有解决方案!

所以它更像是: LandingCtrl(tabBarNotvisible)-> LoginCtrl(tabBarNotvisible)-> profile(tabBarvisible)

这是我尝试过的:

appdelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];

    // Initialize tab controllers.  with each tab has its own navigation controller
    ProfileViewController *profileViewController =[[ProfileViewController alloc]init];
    UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:profileViewController];
    [nav1 setTitle:@"Profile"];

    DiscoverViewController *discoverViewController=[[DiscoverViewController alloc]init];
    UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:discoverViewController];
    [nav2 setTitle:@"Discover"];

    RecievedViewController *recievedViewController = [[RecievedViewController alloc]init];
    UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:recievedViewController];
    [nav3 setTitle:@"Recieved"];

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

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

    LandingViewController *landingviewcontroller = [[LandingViewController alloc] init];
    UINavigationController *nVC = [[UINavigationController alloc] initWithRootViewController:landingviewcontroller];
    nVC = [[UINavigationController alloc]initWithRootViewController:landingviewcontroller];
    nVC.navigationBar.barTintColor = [UIColor colorWithRed:0.204 green:0.286 blue:0.369 alpha:1];
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-100.f, 0) forBarMetrics:UIBarMetricsDefault];
    nVC.navigationBar.tintColor = [UIColor whiteColor];
    nVC.navigationBar.translucent = NO;

    [self.window addSubview:self.tabBarController. view];
    [self.tabBarController presentViewController:nVC animated:YES completion:nil];
    //[self.window setRootViewController:nVC];
    [self.window makeKeyAndVisible];

    return YES;
}

仍然无法让这该死的事情发挥作用,我真的很感谢你的帮助,谢谢!!!!

最佳答案

我正在遵循以下代码。这对我有用,检查一次。您应该先创建登陆页面,然后在登陆页面上创建此逻辑。

NewHomeView *home=[[NewHomeView alloc]initWithNibName:@"NewHomeView_iPad" bundle:nil];
        UIImage *imag=[UIImage imageNamed:@"profile40x40.png"];
        [home setTabBarItem:[[UITabBarItem alloc]initWithTitle:@"Home" image:imag tag:100]];

        BiographyView *biography= [[BiographyView alloc] initWithNibName:@"BiographyView_iPad" bundle:nil];
        UIImage *imag1=[UIImage imageNamed:@"Biography40x40.png"];
        [biography setTabBarItem:[[UITabBarItem alloc]initWithTitle:@"Biography" image:imag1 tag:101]];

        GalleryView *gallery = [[GalleryView alloc] initWithNibName:@"GalleryView_iPad" bundle:nil];
        UIImage *imag2=[UIImage imageNamed:@"Gallery40x40.png"];
        [gallery setTabBarItem:[[UITabBarItem alloc]initWithTitle:@"Gallery" image:imag2 tag:102]];

        VideosView *video = [[VideosView alloc] initWithNibName:@"VideosView_iPad" bundle:nil];
        UIImage *imag3=[UIImage imageNamed:@"Videos40x40.png"];
        [video setTabBarItem:[[UITabBarItem alloc]initWithTitle:@"Videos" image:imag3 tag:103]];


        MoviesView *movies = [[MoviesView alloc] initWithNibName:@"MoviesView_iPad" bundle:nil];
        UIImage *imag4=[UIImage imageNamed:@"Movies40x40.png"];
        [movies setTabBarItem:[[UITabBarItem alloc]initWithTitle:@"Movies" image:imag4 tag:104]];


        NewsView *news = [[NewsView alloc] initWithNibName:@"NewsView_iPad" bundle:nil];
        UIImage *imag5=[UIImage imageNamed:@"news40x40.png"];
        [news setTabBarItem:[[UITabBarItem alloc]initWithTitle:@"News" image:imag5 tag:105]];

        tabController = [[UITabBarController alloc] init];
        [tabController setViewControllers:[NSArray arrayWithObjects:home, biography, gallery,video,movies,news, nil]];

      [self.navigationController pushViewController:tabController animated:YES];

关于ios - iOS7注册或登录后如何显示标签栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25255890/

相关文章:

iPhone:解析具有阿拉伯语内容的 Xml 显示空值

ios - Xamarin iOS 如何检查位置服务是否已关闭或应用级设备位置是否已关闭

ios - Swift Segue 以编程方式需要很长时间

ios - SQL 错误 : Not an Error

objective-c - Xcode 中的(命名)关键字是什么?

ios - 屏幕左/左下角的 UINavigationController 和触摸事件

ios - Ipad 与台式机

ios - UIButton 奇怪的阴影行为

ios - 如何将值传递给嵌入在 NavigationController 中的 viewController

ios - UIApplication.sharedApplication().keyWindow?.rootViewController 卡住了我的应用程序