There is the Main Storyboard, from there three other storyboards with Navigation Controller, each one connected to a 4 view controllers so they use the back button to go back to their respective storyboard. Each Storyboard has a Storyboard reference to return to the Main Storyboard. Problem: each time the secondaries storyboards return to the main storyboard appears a Navigation Bar with
I used the following code in viewDidLoad():
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBarHidden = true
}
and also on viewWillAppear:
override func viewWillAppear(animated: Bool) {
self.navigationController?.navigationBarHidden = true
}
Related
I am using the following code snippet:
let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "secondViewController") as! secondViewController
self.navigationController.pushViewController(secondViewController, animated: true)
I want to execute this code in the viewDidLoad. I will be using something like this in a series of if statements.
I used some code I found here that utilized a label. It did not work. Can a program move from one viewController without using a button? Almost every example, youtube video uses a button. I will be using a button when it is appropriate
You can not push view controllers before your current view controller loads. You should call your code in your viewDidAppear.
If you plan on directing to a particular view when the app launches I suggest you moving your logic to the AppDelegate in the method: didFinishLaunching. This way you don't need to unnecessarily load views.
Example of a ViewController being pushed in the viewDidAppear:
///
/// FUNCTION - VIEW DID APPEAR
///
override func viewDidAppear(_ animated: Bool) {
// GET VIEW CONTROLLER
let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "secondViewController") as! secondViewController
// PUSH VIEW ONTOP OF CURRENT NAVIGATION CONTROLLER
self.navigationController.pushViewController(secondViewController, animated: true)
} // END - FUNCTION
I am new to swift. I have a viewController
Initially the pickerView is hidden but it appears on clicking on textField then it hides again. I want the button hide upon pickeriew selection and then unhide after selection. This is how i am doing it.
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
pickerView.isHidden = false
return false
}
I can hide the backButton like backButton.isHidden = true but it won't show when the selection is done.
Just make visible the back button when picker value is selected and hide the pickerview
func pickerView(pickerView: UIPickerView!, didSelectRow row: Int,
inComponent component: Int)
{
backButton.isHidden = false
pickerView.isHidden = true
}
If you want to to show the picker view during textfield selection, then you need to add picker view as textfield's input view. You can refer this link also https://blog.apoorvmote.com/uipickerview-as-inputview-to-uitextfield-in-swift/
I currently have several labels and buttons in a UIView. I am using Storyboards and I want to add an image to the background. I tried it this way:
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor(patternImage: UIImage(named:"background.png")!)
But unfortunately, this does not look right in the larger screen sizes. I think that I need to add a UIImageView. When I added a UIImageView, I couldn't figure out how to set it to be in the background so my button and labels could still be seen.
let someImageView: UIImageView = {
let theImageView = UIImageView()
theImageView.image = UIImage(named: "yourImage.png")
return theImageView
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(someImageView) //This add it the view controller without constraints
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
someImageView.frame = view.bounds
}
In your storyboard:
1- Add a UIImageView (inside your main view and outside everything else) and set its image to the image you want.
2- setup its constraints properly to fill the screen (give it 0 from all sides).
3- From attribute inspector, set Content Mode property to Aspect Fit.
I solved this problem by going to the panel in Storyboards and moving the UIImageView above the container view that held the labels and buttons. The UIImageView remained inside of the View, but moved to the background (under the buttons and labels).
I am using this pod: https://github.com/jonkykong/SideMenu for my Side bar in my app. I set the side bar navigation through Storyboard. My app design is that I have a main screen, and a side bar with buttons that take me to different screens. The different screens also have the same side bar. My bug is in this situation: I go into the side bar from main screen -> Then I go into screen2 through the side bar -> I click on the side bar from the screen 2 -> Side bar appears from the bottom and takes the whole screen.
For fixing this bug I found a workaround that does NOT satisfy me. I understood I need to dismiss the side bar but then if I want to go into another screen I first see the screen I came from (because I dismiss) and then it only moves to the second screen. I hope this makes sense. I want to achieve switching to the second screen without first seeing the main screen. This is the code that helps me dismiss and then change screens:
dismiss(animated: true, completion: {
goIncident()
})
func goIncident(){
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let window = appDelegate.window
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let rootController = mainStoryboard.instantiateViewController(withIdentifier: "log") as! UINavigationController
window?.rootViewController = rootController
}
Edit: The added photo shows the problem when I only use the function goIncident() without dismissing. If I do dissmiss, I see the home screen and only after the home screen is presented when it calls the new screen to appear.
So I used a very ugly method to solve this, but I believe this is the only possible way, since this Pod is not very flexible, unless I missed something. What I did is this:
In SideBarViewController:
func goLog(){
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "changeLog"), object: self)
}
In MainViewController:
override func viewDidLoad(){
NotificationCenter.default.addObserver(self, selector: #selector(goLog), name: NSNotification.Name(rawValue: "changeLog"), object: nil)
}
func goLog(){
let logViewController = self.storyboard?.instantiateViewController(withIdentifier: "IncidentLogViewController") as! IncidentLogViewController
self.navigationController?.viewControllers = [logViewController]
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "dismissSideBar"), object: self)
}
So the Side bar tells the navigation controller to replace its view controller, and then after its replaced the navigation controller send back a notification to dismiss the the side bar. Pretty ugly but actually works smoothly.
I'm having a problem in Swift 3.0 right now.
As attached picture (a), I embedded navigationController into ViewController.swift. ViewController.swift have button to connect to UITableCell MovementStatusVC.swift. And MovementDetailsVC.swift is to display all value from table cell.
The problem that i'm facing right now is when I create button in MovementDetailsVC.swift and perform segue to pass the data inside "EditData" function, Page display twice.
MovementDetailsVC.swift
import UIKit
class MovementDetailsVC: UIViewController {
#IBAction func EditData(_ sender: Any) {
performSegue(withIdentifier: "EditMovementDetails", sender: self)
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
The EditMovementDetailsVC.swift controller display twice when I tap Edit button in MovementDetailsVC.swift as shown as in picture below.
I'm using perform segue and prepare segue in MovementDetailsVC.swift
How to fix it so the view only perform one time ?
Thanks.