- 在swift中通过 storyboard或者编程的方法 来实现一个 UITabBarController 进行各个UIViewController进行切换
相关阅读:http://makeapppie.com/2014/09/09/swift-swift-using-tab-bar-controllers-in-swift/ - 前面那个方法是放在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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。