Navigation bar disappears when using custom Segue animation - ios

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

Related

Performing a segue navigation controller, but navbar doesn't appear

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

Swift 4 Unwind segue not working on navigation controller

I am working on an app in Swift 4 and I am trying to unwind a segue. I have a Table View Controller, When the user selects a cell, the segue happens to a navigation controller which has a relationship root view controller with another controller I have UIViewController. In the UIViewController I have a UIButton inside Navigation Items, I have unwind set with the UIButton by selecting the button and dragging to exit and I have the unwind code inside the UITableViewController like so:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "segueRSVP" {
}
}
#IBAction override func unwind(for unwindSegue: UIStoryboardSegue, towardsViewController subsequentVC: UIViewController) {
print("Here")
}
But nothing happens, it doesn't even get triggered.
Here are my screenshots:
Add this unwind to your RSVP controller:
#IBAction func unwindToThisViewController(segue: UIStoryboardSegue) {
print("IM BACK")
}
Then control + drag the button in your detail controller up to the exit and select the method: unwindToThisViewController
Just tested this on xcode swift 4 and it should work
I'm not sure why, but when I "overrode" unwind, it didn't work for me either, so I set up my own ibaction
In my case, was tagging the swift unwind func with #objc keyword.
#objc func unwindToThisViewController(segue: UIStoryboardSegue) { ... }
Hope this works.

navigation bar disappear after adding prepare function

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
}

prepare(for segue: UIStoryboardSegue, sender: Any?) Not firing in Xcode 8.1 swift 3 ios 10

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.

How to specify which view controller you are preparing for with Swift's prepareForSegue function?

So I have multiple buttons on one view segue'ing to other views. I have the function prepareForSegue() at the bottom of my code preparing one segue, however the app crashes when I use another segue on the view, even if it doesn't need any preparing.I think that the problem is that all of the segues use the prepareForSegue() function, however the storyboard ID is different than the view it is transitioning to.Is there any way to specify a prepareForSegue() function for each separate segue on the same view?Code:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let theVC: ViewController = segue.destinationViewController as! ViewController
theVC.receivedString = "true"
}
Thanks
In your prepareForSegue you should use a condition to check segue identifier like:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if(segue.identifier == "yourSegueToAnyController")
{
//do code for specific viewController
}
}

Resources