TabBar disappears when programatic segue - ios

I want to segue to a new ViewController programatically but when I do my tabBar disappears.
if user == usernameStored && pass == passwordStored{
print("Good")
let vc = self.storyboard?.instantiateViewController(withIdentifier: "home")
self.present(vc!, animated: true, completion: nil)
}

From your code, this is not segue by programmatically. You actually present a viewController on top of whatever you have. Therefore the tabBarController is cover.
To use segue in code, it should be something like this. - homeSegueID is the identifier you give when you created the segue in storyboard.
performSegue(withIdentifier: "homeSegueID", sender: nil)
If you just want to do it programatically without segue, you could do this instead. (This assume your current ViewController is in a UINavigationController stack.
navigationController?.pushViewController(vc, animated: true)

Is the navigation controller wrapping your view controllers a tab bar controller, or did you just add the tab bar to your view controller? This is what you should be doing:

Related

Pop from one View Controller to another in a different navigation controller

I am trying to pop a view controller VC1 from one navigation controller NC1 to another view controller VC2 in another navigation controller NC2.
I am using the VIPER architecture thus routing between different view controllers in different navigational hierarchies requires that I must switch to the root of the navigation controller I want to present.
So the issue here is that, after navigating to the view controller VC2 of the second navigation controller NC2, I want to go back to the first view controller VC1 in the first navigation controller NC1.
I have tried the following:
self.navigationController?.popViewController(animated: true)
navigationController?.dismiss(animated: true, completion: nil)
view.window?.rootViewController?.dismiss(animated: true, completion: nil)
self.navigationController?.popToRootViewController(animated: true)
but none of them worked for me. Any ideas?
Please Try this codes :
let viewControllers = self.navigationController?.viewControllers
for vc in viewControllers! {
if vc is VC1 {
self.navigationController?.popToViewController(vc as! VC1, animated: true)
}
}

How To Remove The First ViewController In The Background?

I have two view controllers, first view controller and the second view controller, when the user segue from the first view controller to the second view controller, the first view controller still visible and sits behind the second view controller. The user can swipe the first view controller and see the entire first view controller and then they got stuck there. I noticed that this only happens after the launch of iOS 13.
performSegue(withIdentifier: "showSecond", sender: self)
Follow these two steps:
Click on the segue you created on the Storyboard
Go to Attributes Inspector
Set the Presentation to "Full Screen"
#Maysam is 100% right! But you can also do it programmatically through this:
// Go to next View Controller
#IBAction func nextTextVC(_ sender: UIButton) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let nextInfo = storyboard.instantiateViewController(identifier: "socialOptionsIntroViewController")
self.navigationController?.pushViewController(nextInfo, animated: true)
}
There is a more detail thread could answer this question.
The follow solution from Pratik Sodha
let controller = UIViewController()
let navigationController = UINavigationController(rootViewController: controller)
navigationController.modalPresentationStyle = .overCurrentContext
self.navigationController?.present(navigationController, animated: true, completion: nil)

Navigation pushViewController is not working

i have login view controller. when usersingin i' showing popup for that i
refereed
https://www.youtube.com/watch?v=S5i8n_bqblE i can achieved that.
popup had button when i click the button navigation to next view controller
but its now working when i am clicking that action is performing but its not navigating to next view controller wher i did mistake
Singin
class DigitalGateViewController: NANavigationViewController
{
#IBAction func singin(_ sender: UIButton)
{
let lv = NAViewPresenter().activityVC()
self.present(lv, animated: true)
}
}
this is popupviewcontroller
class ActivityViewController: NANavigationViewController {
#IBAction func okbuttonclick() {
let dv = NAViewPresenter().myGuestListVC()
// self.navigationController?.pushViewController(dv, animated: true)
}
}
its not push to textview controller in swift
When you present a view controller, its presented modally and is not pushed onto the previous navigation controller's stack. Hence, you tried to call self.navigationController?.pushViewController(), it doesn't work, because self i.e. NAViewPresenter().myGuestListVC() isn't embedded in a navigation Controller.
If you want to push the new VC onto the previous stack, you will have to dismiss the presented pop up and then push. The easiest way to do this is to use a delegate method.
Edit:
if you want to create a new navigationController, you can do something like this :
let navController = UINavigationController(rootViewController: NAViewPresenter().myGuestListVC())
present(navController, animated: true)
After presenting the navController, you can use self.navigationController.push method henceforth.
The reason why its not pushing because you are presenting it modally not pushing on the navigation stack and so it wont have any navigationController. If you want to push from your modal popup, you can access the property presentingViewController on your modal object and try to push it on navigationController from there.
self.presentingViewController?.navigationController?.pushViewController(myVC, animated: true)
dismiss(animated: true, completion: nil)

Why doesn't my UIButton segue behave like a UITableViewCell segue?

I am trying to create segues between my UIViewControllers but am having some difficulties with creating a segue from a UITableViewCell and a UIButton.
When I create a show detail segue through storyboard from a UITableViewCell to a UIViewController it works perfectly and I get the back button showing up. But when I try to create a show detail segue from a UIButton to a UIViewController it doesn't register the navigation stack and presents the screen modally without the back button.
How can I make a successful show detail segue from a UIButton to a viewcontroller? I am new to iOS and am having trouble determining why the UIButton segue doesn't behave the same as the UITableViewCell segue.
Thanks in advance for any help!
Dont connect a segue manually do it through button action.
This is assuming the viewController that has this button is the root view controller of the navigation controller
#IBAction func myButtonTapped(_ sender: Any) {
let vc = self.storyboard!.instantiateViewController(withIdentifier: "YOUR STORYBOARD IDENTIFIER GOE HERE")
self.show(vc, sender: self)
}
If you want to go to a tab of a tab bar controller you have to specify its index. I think you can set it in storyboard but i just go with 0 is on the left then they go up sequentially. so in the example below i want to go to the second tab of the tab bar controller with a modal transition. I assume you can use show here like example above I've just never done it.
let tbc = self.storyboard!.instantiateViewController(withIdentifier: "MyTabController") as! UITabBarController
tbc.selectedIndex = 1 // this is 2nd tab index.. start at 0
tbc.modalPresentationStyle = .overCurrentContext
tbc.modalTransitionStyle = .coverVertical
self.present(tbc, animated: true, completion: { finished in
// you can also do some completion stuff in here if you require it.
// self.view.removeFromSuperview()
// self.navigationController?.navigationBar.removeFromSuperview()
})
let vc = self.storyboard!.instantiateViewController(withIdentifier: "StoryBoardID")
self.navigationController?.pushViewController(vc, animated: true)

pushViewController Not Pushing A New View

I have two view controllers and a button in my storyboard. I don't understand why this is not pushing the view to the second view controller. I have the Storyboard ID and Class of FirstViewController, so shouldn't it work? I keep getting this error Unknown class FirstViewController in Interface Builder file. What am I doing wrong?
#IBAction func button(sender: AnyObject) {
let viewController = self.storyboard?.instantiateViewControllerWithIdentifier("FirstViewController")
self.navigationController?.pushViewController(viewController!, animated: true)
}
Just to have an answer for others -->
Two ways to solve it ->
1.Add a navigationController in the storyboard, as you cannot do pushViewController on a viewController outside navigationController's stack.
2.You can push it as a modal view controller, using self.presentViewController(viewController, animated: true, completion: nil)
This will give a modal effect, and not the normal push effect.

Resources