zoukankan      html  css  js  c++  java
  • TabBar实现页面跳转(AppDelegate +NavigationViewController + TabBarViewController)

    1. AppDelegate.h

     定义TabBarController

    #import <UIKit/UIKit.h>

     

    @interface AppDelegate : UIResponder <UIApplicationDelegate>

     

    @property (strong, nonatomic) UIWindow *window;

    @property (strong, nonatomic) UITabBarController *tabBarController;

    @end

     

    2.AppDelegate.m

     

    #import "AppDelegate.h"

    #import "FirstViewController.h"

    #import "SecondViewController.h"

    #import "ThirdViewController.h"

     

    @interface AppDelegate ()<UITabBarControllerDelegate>

     

    @end

     

    @implementation AppDelegate

     

     

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

        

        self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];//实例化window

        self.window.backgroundColor = [UIColor whiteColor];//设置window背景

        

        _tabBarController = [[UITabBarController alloc]init]; //实例化选项卡控制器

        _tabBarController.delegate = self; //将AppDelegate设置成选项卡控制器的代理???

        //实例化3个控制器

        FirstViewController *firstViewController = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];

        SecondViewController *secondViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];

        ThirdViewController *thirdViewController = [[ThirdViewController alloc]initWithNibName:@"ThirdViewController" bundle:nil];

        //实例化3个导航器,将每个控制器的对象都放到导航器的跟控制器的方法中

        UINavigationController *navFirst = [[UINavigationController alloc]initWithRootViewController:firstViewController];

        navFirst.title = @"花时间";

            

        UINavigationController *navSecond = [[UINavigationController alloc]initWithRootViewController:secondViewController];

        navSecond.title = @"花会友";

     

        UINavigationController *navThird = [[UINavigationController alloc]initWithRootViewController:thirdViewController];

        navThird.title = @"";

        //将导航器对象都放到选项卡的子控制器(viewcontroller)中

        _tabBarController.viewControllers = [NSArray arrayWithObjects:navFirst,navSecond,navThird, nil];

       //设置UIWindow的rootViewController为UITabBarController

        _window.rootViewController = _tabBarController;

        [self.window makeKeyAndVisible];

        return YES;

    }

    3.每个UIViewController都设置一下TabBarItem的标题

    FirstViewController.m

    #import "FirstViewController.h"

    #import "AppDelegate.h"

     

    @interface FirstViewController ()<UITableViewDataSource,UITableViewDelegate>{

        

        NSMutableArray *_allFlowers;

    }

     

    @end

     

    @implementation FirstViewController

     

    -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{

        

        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

        if (self) {

            self.tabBarItem.image = [UIImage imageNamed:@"first.png"];

            self.tabBarItem.title = @"花时间";

            

            self.navigationItem.title = @"花时间";

        }

        

        return self;

    }

     

  • 相关阅读:
    pip或easy_install安装库报错:SSL: CERTIFICATE_VERIFY_FAILED
    js 闭包
    php 安装xdebug进行调试(phpstorm)
    Linux下一个最简单的不依赖第三库的的C程序(2)
    Linux下一个最简单的不依赖第三库的的C程序(1)
    windbg .net 程序的死锁检测 常用方法(个人备份笔记)
    自定义经纬度索引(非RTree、Morton Code[z order curve]、Geohash的方式)
    通过经纬度坐标计算距离的方法(经纬度距离计算)
    根据2个经纬度点,计算这2个经纬度点之间的距离(通过经度纬度得到距离)
    The version of SOS does not match the version of CLR you are debugging; SOS.dll版本不匹配; Dump文件不同环境mscordacwks.dll版本问题
  • 原文地址:https://www.cnblogs.com/yuyu-2012/p/4739033.html
Copyright © 2011-2022 走看看