Navigation + Tab Bar 常用組合架構

來源:互聯網
上載者:User

        

看到很多項目中都採用的是Navigation加Tab Bar組合到一起,完成視圖切換操作,在導覽列上添加基本按鈕,給予回應時間,讓應用給使用者更好的體驗,所以本菜鳥寫了這個這樣一個Demo,僅供學習


所建立工程模板是最後一個 Empty Application

      

先看運行效果:


第一個視圖,點擊按鈕切換視圖,點擊導覽列上按鈕可以切換回去

     


第二個視圖設定了背景顏色和透明度  第三個視圖添加了背景圖片


    


第四個視圖,在導覽列上添加了兩個按鈕,左邊按鈕屬於自訂標題,右邊按鈕是系統的表徵圖,點擊左按鈕彈出一個警告,右邊按鈕沒有添加響應事件,點擊後沒反應


     


Tab Bar上添加的都是自訂圖片


架構組合的主要代碼,在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];        _tabBarController = [[UITabBarController alloc] init];    _tabBarController.delegate = self;        FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];        SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"secondViewController" bundle:nil];        ThirdViewController *thirdViewController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];        FourViewController *fourViewController = [[FourViewController alloc] initWithNibName:@"FourViewController" bundle:nil];        UINavigationController *navFirst = [[UINavigationController alloc] initWithRootViewController:firstViewController];//    在載入圖片是把標題都覆蓋了,所以運行效果並沒有顯示這些文字    navFirst.title = @"第一個視圖";        UINavigationController *navSecond = [[UINavigationController alloc] initWithRootViewController:secondViewController];    navSecond.title = @"第二個視圖";        UINavigationController *navThird = [[UINavigationController alloc] initWithRootViewController:thirdViewController];    navThird.title = @"第三個視圖";        UINavigationController *navFour = [[UINavigationController alloc] initWithRootViewController:fourViewController];    navFour.title = @"第四個視圖";            _tabBarController.viewControllers = [NSArray arrayWithObjects:navFirst,navSecond,navThird,navFour, nil];    _window.rootViewController = _tabBarController;        [self.window addSubview:firstViewController.view];    [self.window makeKeyAndVisible];    return YES;}

第一個視圖切換按鈕響應事件

- (IBAction)switchView:(id)sender {        FirstViewController *firstController = [[FirstViewController alloc] init];    [self.navigationController pushViewController:firstController animated:YES];    firstController.title = @"第一個視圖另一個視圖";}

第四個視圖添加兩個按鈕方法,在最後一個控制機的.m檔案中的-(void)viewDidLoad方法中


- (void)viewDidLoad{    [super viewDidLoad];// Do any additional setup after loading the view.    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"測試"                                                                   style:UIBarButtonItemStylePlain target:self                                                                  action:@selector(pullWarn)];    self.navigationItem.leftBarButtonItem = leftButton;        UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:nil];    self.navigationItem.rightBarButtonItem = rightButton;}


原始碼:http://download.csdn.net/detail/duxinfeng2010/4576308







聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.