【问题标题】:Swift, present a new uiview with tab barSwift,呈现一个带有标签栏的新 uiview
【发布时间】:2016-05-03 22:14:11
【问题描述】:

单击表格视图单元格中的按钮后,我试图呈现一个新视图。视图可以显示,但没有标签栏。有没有用标签栏显示视图的解决方案?谢谢。

Storyboard Screenshot

使用 segue 或 progammatically 是不对的。

  func viewDetailAction(sender: UIButton){
    let vc = self.storyboard?.instantiateViewControllerWithIdentifier("patientDetailVC    ") as! PatientDetailViewController
  //        self.presentViewController(vc, animated: true, completion: nil)
 //        self.navigationController?.pushViewController(vc, animated: true)
     self.performSegueWithIdentifier("patientDetailCell", sender: self)
    }

【问题讨论】:

    标签: swift tabbar uitabcontroller


    【解决方案1】:

    更简单的方法是自己展示 VC

     self.presentViewController(vc, animated:true, completion:nil)
    

    这将在你当前的 VC 上而不是在 tab barController 上显示它,因为它可能在故事板 segue 中完成

    请忽略任何代码语法错误。

    【讨论】:

    • 我已经尝试过这种方式,但它不起作用。仍然获得没有底部标签栏的视图
    • 代码中的 cmets 显示您使用了 self.present 而不是 self.tabBarController.present
    • 谢谢你。 self.tabBarController?.presentViewController(vc, animated:true, completion:nil)。它不工作
    【解决方案2】:

    试试,

    vc.modalPresentationStyle = .OverCurrentContext
    

    instantiateViewControllerWithIdentifier之后。

    编辑:(使用 segue)

    简单地,删除show segue并使用Present Modally segue,点击segue,确保Over Current Context演示。

    然后仅在您的操作中使用:

    self.performSegueWithIdentifier("overNewPage", sender: nil)
    

    您可以使用 prepareForSegue 方法访问其属性。

    编辑:(使用 instantiateViewControllerWithIdentifier)

            let viewController = self.storyboard?.instantiateViewControllerWithIdentifier("patientDetailVC") as! PatientDetailViewController
            viewController.modalPresentationStyle = .OverCurrentContext
            viewController.someString = "youCanPassData"
    
            self.presentViewController(viewController, animated:true, completion:nil)
    

    【讨论】:

    • vc.modalPresentationStyle = .OverCurrentContext self.presentViewController(vc, animated: true, completion: nil),,, not working :(
    • @JaniceZhan 更新了我的答案。
    • 我按照您的步骤操作,但仍然无法正常工作。太烂了!
    • @JaniceZhan 有两种不同的方法,你做错了什么。确保您的 Storyboard ID 对于第二条路径是正确的。他们和我一起工作。
    • @JaniceZhan 对于第一个路径,请从 ViewController 连接您的 segue,而不是直接从您的按钮连接。如果你喜欢直接做,你不需要使用self.performSegueWithIdentifier("overNewPage", sender: nil)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-16
    • 2016-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多