I'm segueing to a view linked with a UINavigationController, but the UINavigationBar doesn't appear. There is no sign of the UINavigationController whatsoever.
My StoryBoard looks like this:
To perform the segue, I'm using this:
self?.performSegue(withIdentifier: "practicemod", sender: self)
The preparation function looks like this:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
var vc = segue.destination as! PracticesView
vc.practices = sdkPractices
vc.consumer = sdkConsumer
}
Can someone help me out here? What am I missing?
The start point in your storyboard need to be Navigation Controller.
OR
segue from select view to Navigation Controller to TableView Controller (PracticesView).
This should solve your problem
Related
How do I replace a ViewController and also send some parameters?
With the code below, I can only push another ViewController into my current Navigation Stack.
Can we just pop and push another one immediately? Or is there an official to replace for good? Please kindly show me. Thank you.
Perform Segue
performSegue(withIdentifier: "ToNewViewController", sender: self)
Prepare Segue
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destinationVC = segue.destination as! NewViewController
destinationVC.params = params
}
If you have a navigation controller as your app window root , then you can manage all viewControllers
var vcs = self.navigationController!.viewControllers // get all vcs
vcs = vcs.dropLast() // remove last vc
let vc = // create new VC
vcs.append(vc) // append it
Then alter that array and set it back like this
self.navigationController!.setViewControllers(vcs,animated:true)
OR
You can get the top presented vc with this , then add a method to that vc to do the data replacement and refresh of your UI
I am woking on an recording APP.
I tried to add navigation controller in my first recording viewcontroller which then could pass filename array to the second viewcontroller using the following function prepare:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let controller = segue.destination as? MainViewController
controller?.recordArray = recordingArray
self.present(controller!, animated: true, completion: nil)
}
However, when ran in the simulator the navigation bar disappeared in the second controller and Xcode pops out the warning
Thread1: EXC_BAD_ACCESS(code=2,address=0x7fff51edfff8)
Has anyone got any advice?
Thanks!
Don't ever call present(_:animated:completion:) inside prepare(for segue:).
prepare(for segue) is called automatically by the system just before a segue is about to happen to let you prepare the data for sending to the destination viewcontroller or do any other calculations you need to before performing the segue. A segue needs to be set up in Storyboard and it will either be called automatically or if it is a manual segue, you need to call it using perform(segue) and once you do that, the system will call prepare(for segue) for you. You can see why calling another navigation function proves to be problematic, since you are trying to navigate to another viewcontroller using two different methods (segue and present).
If you haven't set up the segue in Storyboard, then you also need to do that, since if it is not set up, let controller = segue.destination as? MainViewController will be nil.
Once you set up the segue in Storyboard, this is how your function should look like:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let controller = segue.destination as? MainViewController {
controller.recordArray = recordingArray
self.present(controller, animated: true, completion: nil)
}
}
You shouldn’t be trying to present a VC in this method, it’s just a place for you to configure the destination VC before the segue presents it
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard let controller = segue.destination as? MainViewController else { return }
controller.recordArray = recordingArray
}
i'm trying to use custom segue animations in my app, however whenever i perform the segue the navigation bar disappears in the following VC. The animation and segue does work though
//calling prepare function and using .growscale animation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue is CustomSegue {
(segue as! CustomSegue).animationType = .growScale
}
}
//button performs Segue
#IBAction func exerciseLibrary(_ sender: UIButton) {
self.performSegue(withIdentifier: "customSegue", sender: self)
}
I set the segue to custom as well, and i hope this is of any help but the VC that i am segueing to is a Collection View Controller
Update: Storyboard storyboard-main
Here is a picture of my storyboard:
I assume the problem is because the segue is coming from a custom table view cell. The button will send information based on the cell selected. When I press the button, I just perform the segue with identifier. Unfortunately, the navigation bar does not appear, and I can't imagine why its not appearing.
Any help is greatly appreciated!
EDIT: Here is the storyboard segue. It is push:
EDIT2: Here is the code I am using to perform this segue:
func buttonAction(sender: UIButton!) {
segueIndex = sender.tag
performSegue(withIdentifier: "segue_show_job", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "segue_show_job" {
let nextVC = segue.destination as! PlaceBidTableViewController
nextVC.job_info.job_info = self.job_arr_arr.job_info_arr_arr[segueIndex]
}
}
ANSWER:
Maximo and XCoder, thank you for your help. Even though my segue was push, something must have been corrupted. I deleted the segue and re-created it and it worked! Thanks!
Make sure use Push in your view. This is what suppose to be.
This make your navigation bar not show up.
Maximo and XCoder, thank you for your help. Even though my segue was push, something must have been corrupted. I deleted the segue and re-created it and it worked! Thanks!
I have a tabbed view controller that is associated with two view controllers.
I need to pass an array from the first View Controller to the Second View controller.
In Order to do this I have the following code in my first VC:
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
{
if segue.identifier == "AddItem"
{
if let destinationVC = segue.destination as? SecondViewController
{
destinationVC.toDoList = toDoList
}
}
}
However this is not getting fired when I switch two the second VC using the tab button.
Any ideas as to why this is not getting fired?
This is how my main storyboard looks like:
Main Storyboard
You cannot transfer objects between tab views through segue because the VC is not actually making a direct segue connection rather you can do it with a delegate or a notificationCenter post and observe to transfer
You have to put that segue code in Tabbar controller class. You shouldn't put that thing in firstVC. Because there is no segue is going on from first VC to Second VC.