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!
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 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.
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.
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 profile that is embedded in a navigation controller. When I create a segue that goes to another view controller (also embedded in a navigation controller), I get the screen below. I used to seeing the back button that, in this case, would say "< Profile" but all I see is a blank nav bar with no back button, SOS!
Can anybody help me fix this issue? I can't seem to find any help!
This is the code I have written for the segue to go from the profile view controller to the followers view controller, which is the one with the blank nav bar.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "toFollowers" {
var profileVC: FollowersViewController = segue.destinationViewController as! FollowersViewController
profileVC.followers = true
}
}
Are you setting hidesBackButton = YES or backBarButtonItem = nil in
profileVC, or does it have a different leftBarButtonItem
defined?
Have you remove back via programmatically please remove those code.
EDITED
Following code returns how many controllers into UINavigationController please check it out it's greater then 0 or not.
var stack = self.navigationController!.viewControllers as Array
May this helps lot.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "toFollowers" {
//Try getting the navigation controller first as
var navVc = segue.destination as UINavigationViewContrller
//than
var profileVc = navVc.viewControllers.first as! FollowersViewController
// var profileVC: FollowersViewController = //segue.destinationViewController as! FollowersViewController
// profileVC.followers = true
}
}