Janice Zhan
Janice Zhan

Reputation: 571

Swift, present a new uiview with tab bar

I am trying to present a new view after click button in a tableview cell. The view can show up but without the tab bar. Is there any solution that showing the view with tab bar? Thanks.

Storyboard Screenshot

Using segue or progammatically are not right.

  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)
    }

Upvotes: 0

Views: 1999

Answers (2)

iamburak
iamburak

Reputation: 3568

Try,

vc.modalPresentationStyle = .OverCurrentContext

after instantiateViewControllerWithIdentifier.

Edit: (using segue)

Simply, delete show segue and use Present Modally segue, click on segue, be sure Over Current Context presentation.

And then use in your action only:

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

You can reach its properties using prepareForSegue method.

enter image description here

Edit: (using instantiateViewControllerWithIdentifier)

        let viewController = self.storyboard?.instantiateViewControllerWithIdentifier("patientDetailVC") as! PatientDetailViewController
        viewController.modalPresentationStyle = .OverCurrentContext
        viewController.someString = "youCanPassData"

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

Upvotes: 1

Shubhank
Shubhank

Reputation: 21805

A easier way is to present the VC yourself

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

This will present it on your current VC and not on the tab barController as it is being done probably in the storyboard segue

Please ignore any code syntax mistakes.

Upvotes: 1

Related Questions