swift 中使用tabbar 来控制viewController跳转

  1. 在swift中通过 storyboard或者编程的方法 来实现一个 UITabBarController 进行各个UIViewController进行切换
    相关阅读:http://makeapppie.com/2014/09/09/swift-swift-using-tab-bar-controllers-in-swift/
  2. 前面那个方法是放在AppDelegate中实现的。而现实项目中可能有需要在某个界面上,点击一个按钮,弹开一个包含有UITabBar的视图,然后在各个ViewController之间进行切换
    主要思路是:
    • 建立一个继承UITabBarController类 ,并且实现委UITabBarDelegate
//
//  ChartViewController.swift
//  iLiveTraffic
//
//  Created by 徐泽宇 on 15/8/14.
//  Copyright (c) 2015年 徐泽宇. All rights reserved.
//

import UIKit

class ChartTabBarController: UITabBarController,UITabBarDelegate {


    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem!) {
        NSLog("tabbar item 被点击")
        switch item.tag{
            case 0:
                //是退出按钮
                self.dismissViewControllerAnimated(true, completion: nil)
            case 1:
                NSLog("点击图表1")
            case 2:
                NSLog("点击图表2")
            case 3:
                NSLog("点击图表3")
            case 4:
                NSLog("点击图表4")
            default:
                NSLog("未知按钮")
        }
    }
}
  • 在storyboard中建立UITabBarController和各个UIViewController之间的关系
    这里写图片描述
  • 在需要打开这个UITabBarController 地方弹开这个TabBarController
var chartTabBarController: ChartTabBarController! = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("chartTabBarController") as! ChartTabBarController
presentViewController(chartTabBarController, animated: true, completion: nil)

相关阅读:
http://blog.csdn.net/totogo2010/article/details/7700291

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值