How to fix new view display after segue? - ios

I just recently started coding again after about four months. There were a few updates in between. When I went to work on my app I clicked on a link and noticed the new view was hovering over the last view and there was no status bar. Just wanted to know what is causing this to happen and how to fix? Thanks
self.performSegue(withIdentifier: "Recover=>SignIn", sender: self)
override func prepare(for segue: UIStoryboardSegue, sender: Any!) {
if(segue.identifier == "Recover=>Connection") {
let navController = segue.destination as! UINavigationController
_ = navController.topViewController as! Connection
}
}

iOS 13 changed the way view controllers are presented by default. If you are using something like
parentViewController.show(childViewController, sender: self)
In iOS 12 the child view controller used to be shown full screen. In iOS 13 it shows up hovering over its parent.
To make it show up full screen, you need to add one line above the show():
childViewController.modalPresentationStyle = .fullScreen.

Related

reset variables when pass to an another ViewController

my problem is that when i switch to an another ViewController, my variables of the previous VC call are reset so i can't do what i want after
#IBAction func BackBtn(_ sender: Any) {
self.nbrQst = 10
self.Switch1A = 2
performSegue(withIdentifier: "Numero", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "Numero" {
let vc = segue.destination as! ViewController
vc.nbrQt = nbrQst
}
if segue.identifier == "Numero" {
let vcNv = segue.destination as! ViewController
vcNv.Switch1 = Switch1A
}
}
below the way that i send information from my Lvl1 file to the lvl selector file to add a if else for unblocks the lvl
#IBAction func BackBtn(_ sender: Any) {
self.nbrQst = 10
self.Switch1A = 2
performSegue(withIdentifier: "Numero", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let vc = segue.destination as! ViewController
vc.nbrQt = nbrQst
vc.Switch1 += 2
}
that's the second ViewController who send the number to the first one, and i want that the first one remember the number and add them up each time I press the button that sends the numbers
Let's call "Selector VC" the main VC.
The reason why those numbers reset in main VC is that when you press the "BackBtn", you're not actually going back to main VC, you're creating a new main VC and going there (because you did performSegue(withIdentifier: "Numero", sender: self) in BackBtn function, performSegue always takes you to a new VC rather than taking you back). The new main VC has all those fields starting from an initial number (I assume initially they're zero).
What you want to do is to go BACK, not forward. Depending on how you went to the level VC from main VC, you have different ways of going back to main VC.
If you're pushing everything onto a navigation controller, then you can go back by:
self.navigationController?.popToRootViewController(animated: true)
If you're presenting everything modally, you can go back by
self.dismiss(animated: true, completion: nil)
You said, you want to update the value in main VC so that you can block/unblock next level. A very standard way to achieve this is via delegate, please Google this ("delegates in Swift") and follow their tutorials there.
I strongly recommend that you take an online course on swift development before you go ahead and develop your own app, because you could potentially do a lot of things wrong and waste a lot of your time trying to get an answer from Stack Overflow.

Having trouble "reaching" my override prepare function to programmatically change views in a tab bar controller

I have a view controller with a container view that has a tab bar controller embedded in it. Im using this to display 3 different view controllers based on what is pressed from a segmented control in the main vc. I have been following this solution: https://stackoverflow.com/a/38283669/11536234
My problem is that when I change the segmented control index (by pressing a different segment) I can't figure out how to "reach" the prepare function.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
print("prepare reached")
//super.prepare(for: segue, sender: sender)
//switch(segue.identifier ?? "") {
//case "TabBar":
guard let TabController = segue.destination as? UITabBarController else {
fatalError("Unexpected destination: \(segue.destination)")
}
TabController.selectedIndex = toggle.selectedSegmentIndex
//default:
//fatalError("Unexpected Segue Identifier; \(segue.identifier)")
//}
}
#IBAction func toggleAction(_ sender: UISegmentedControl) {
print("toggle is now at index: ", toggle.selectedSegmentIndex)
//performSegue(withIdentifier: "TabBar", sender: sender)
//container.bringSubview(toFront: views[sender.selectedSegmentIndex])
}
So far i have tried placing a performsegue function in an action function linked to the segmented control. This doesn't work, however, because it essentially adds another embedded tab bar programmatically or calls the embed segue again and I receive this error statement: "There are unexpected subviews in the container view. Perhaps the embed segue has already fired once or a subview was added programmatically?"
*The commented lines of code are there to show what I've tried that hasn't worked vs where I'm at.
When you embed a view controller to a container view from another view controller(MainVC), the segue is performed only once when MainVC loads. To pass values to the embedded UIViewController/UITabBarController, you need to get the child view controller and send the data
class MainVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func segmentControlAction(_ sender: UISegmentedControl) {
if let tabBarVC = self.children.first(where: { $0 is UITabBarController }) as? UITabBarController {
tabBarVC.selectedIndex = sender.selectedSegmentIndex
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
//called before mainvc viewDidLoad
let destinationVC = segue.destination as? UITabBarController
destinationVC?.selectedIndex = 1
}
}
You can't do what you are trying to do.
With embed segues the segue fires when the host view controller is first loads. That invokes your prepare(for:sender) method, once and only once, before the embedded view controller's views are loaded. It doesn't get called again.
What you need to do is to save a pointer to your child view controller in an instance variable. Define a protocol that the parent uses to talk to the child, and then use that protocol to send a message to the child when the user selects a different segment in your segmented control.
Then the child (presumably the tab bar controller) can switch selected tabs in response to the message you define.

Swift - Navigation Bar Not Appearing From Segue From Custom Cell

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!

iOS - Navigation bar has no back button

I am currently using a walkthrough view controller to show a "getting started" carousel when you first open my app. Once you select get started, there are two buttons at the bottom that direct you to login as one of two types of users:
However, As you can see here there is no back button to take you back to the page where you decide what type of user you are. Here is the code I am using to segue:
override open func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let NavViewController = segue.destination as! UINavigationController
let NextViewController = NavViewController.topViewController as! LoginViewController
if(segue.identifier == "client") {
NextViewController.request = 0;
} else {
NextViewController.request = 1
}
}
In addition, I have added titles to all of the other view controllers in their viewDidLoad() methods. If anyone has an idea of why the back button isn't showing, I would greatly appreciate your help!
Question has been answered by Grundewald. Solution: The navbar needs to begin before the initial segue. Thank you for your help!

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.

Resources