简体   繁体   English

使用tabBar从应用程序中的navBar推送视图

[英]Push view from navBar in app with tabBar

Im attempting to make an app that has both a UITabBar (as the root view controller) and also a UINavigationBar that are both consistently present throughout the app. 我试图制作一个既有UITabBar (作为根视图控制器)又有UINavigationBar的应用程序,这些应用程序在整个应用程序中始终存在。 My issue is that I'm trying to push a viewcontroller from the navBar but I can not find out how to do so. 我的问题是我试图从navBar推送一个viewcontroller,但是我不知道该怎么做。 I understand that I need the UINavigationBar to be the NavigationController of the view controller I'm trying to push from but I cannot figure out how to do this. 我知道我需要UINavigationBar成为我要从中推送的视图控制器的NavigationController ,但是我不知道该怎么做。

In appDelegate: 在appDelegate中:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    let tabBar = window!.rootViewController
    let navBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: window!.frame.width, height: 64))

    let navBarItem = UINavigationItem(title: "Title")
    navBar.items = [navBarItem]

    tabBar?.view.addSubview(navBar)

    return true

}

In ViewController im trying to push new VC from 在ViewController中,我试图从中推送新的VC

override func viewDidLoad() {
    super.viewDidLoad()

    let navBar = self.parentViewController?.view.subviews[2] as! UINavigationBar
    let navBarItem = navBar.items[0] as! UINavigationItem

    navBarItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "pushCreateVC:")
}

func pushCreateVC(sender: UIBarButtonItem) {

    println("push")

    let navBar = self.parentViewController?.view.subviews[2] as! UINavigationBar
    let navBarItem = navBar.items[0] as! UINavigationItem //left over code to reference the navBar from this method

    let createVC = CreateViewController()
    self.navigationController?.pushViewController(createVC, animated: true) // This is where I want the navBar to push createVC so it still have the navBar at the top with a back button

}

if you wanna do what you mention in the question, you should create a UITabbarController with UINavgationController(s) in it 如果您想做在问题中提到的事情,则应使用UINavgationController创建一个UITabbarController

//        First you need to create a nav controller with viewcontroller in it

var vc = UIViewController()
var navController = UINavigationController(rootViewController: vc)

var tbController = UITabBarController()

//you can add more tab with more navControllers or viewcontrollers
tbController.setViewControllers([navController], animated: true)

//present the tbController as the main viewcontroller

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 标签栏内的导航栏内的iPhone推送视图控制器 - iphone push view controller inside navbar inside tabbar 如何从Tabbar控制器获取UINavigation控制器并推送特定视图 - How to get UINavigation controller from Tabbar controller and push a specific view 如何从其他选项卡中在tabbar中推送其他视图? - How to push other view in tabbar from other tab? 如何处理标签栏的推送通知,其中我的标签栏控制器距离根视图控制器较远 - How to handle the push notifications for a tabbar, where my tabbar controller is far away from the root view controller 搜索到标签栏和导航栏中的视图控制器 - Segue to a view controller that's within a tabbar and navbar 具有Navbar和Tabbar的UIScroll和具有动态高度的容器视图 - UIScroll with Navbar and Tabbar and container view with dynamic height 根ViewController视图未考虑TabBar和NavBar - Root ViewController View is not taking TabBar and NavBar into account 从视图中删除tabBar - Remove tabBar from view 旋转视图 iPhone 标签栏应用 - Rotate view iPhone tabbar app 如何使用变量中的某些数据推送到tabbar中查看? - How to push to view in tabbar with some data in a variable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM