Logout button in every viewcontroller in swift 5

Related searches

I'm new in iOS. I've implemented an login section. Login is working fine. But after login, I'm adding a button (logout) manually. After clicking it, logging out from the app.

Can I make a header which will have Home and Logout link? So that I won't have to recode same thing in all viewcontroller.

EDIT:- I've achieved this. I'm posting the solution as an answer.

I think you want to use UINavigationController which will contain your view controllers and then add UIBarButtonItems to the navigationController which will persist across all viewControllers

Swift Login / Logout Navigation Process | by Paul Allies, Here I show a “login” view controller when user is not logged in otherwise show a tab bar Swift Login / Logout Navigation Process DONE!! Any improvements/ suggestions are most welcome!! Easy Google Maps Setup Tutorial— Swift 5 A button that says 'Download on the App Store', and if clicked it. Every app has at least one view controller, but most apps have many more. A view controller typically manages a single User Interface (UI) or “screen” in your app. It also manages interactions between the UI and the underlying data, better known as models. Let’s take a look at the Swift code for a simple view controller:

I am working on a big app as well , this works for me , i am using to to manage logout from any ViewController :

       let loginVC = self.storyboard?.instantiateViewController(withIdentifier: "loginVC") as! MMLoginViewController

       let appDel:AppDelegate = UIApplication.shared.delegate as! AppDelegate

       appDel.window?.rootViewController = loginVC

Best Practice for iOS Login / Logout With Animation & Without , As we all know, the scope of mobile application is growing day by day. May 20, 2018 � 5 min read This post aims to show best practice in iOS Login / Logout without storyboard Let's forget the initial view controller and set root view controller manually. Finally, if we run the application, each button works properly. In most cases a View Controller shows one screen to a user, but the user can interact with the screen in multiple ways. Every one of these interactions is handled differently in code. This can be…

I've created an UILibraryFunction.swift file.

class UILibraryFunction: UIViewController {

var navBar:UINavigationBar = UINavigationBar()
var navItem = UINavigationItem(title: "SomeTitle")

var screenWidth:CGFloat = 0
var screenHeight:CGFloat = 0

var NameHeight:CGFloat = 0
var NameWidth:CGFloat = 0

override func viewDidLoad() {

    let screenSize: CGRect = UIScreen.main.bounds

    screenWidth = screenSize.width
    screenHeight = screenSize.height

    NameHeight = screenHeight * 0.09
    NameWidth = screenWidth
    navBar = UINavigationBar(frame: CGRect(x: 0, y: 30, width: NameWidth, height: NameHeight))

    navBar.setItems([navItem], animated: false)


//---- Right Bar Button -----
func rightBarButton() {
    let rightBarButton = UIBarButtonItem(title: "Logout", style: UIBarButtonItem.Style.plain, target: self, action: #selector(Lge3Generell.Logout(_:)))
    navItem.rightBarButtonItem = rightBarButton


//--- Left Bar Button -----
func leftBarButton() {

    let leftBarButton = UIBarButtonItem(title: "Home", style: UIBarButtonItem.Style.done, target: self, action: #selector(self.GoToHome(_:)))
    navItem.leftBarButtonItem = leftBarButton


//----- UI Bar Title ----
func setTitle(BarTitle:String) {
    navItem = UINavigationItem(title: BarTitle)
    return navBar.setItems([navItem], animated: false)


Now I call this 3 function in all of my ViewController 's ViewDidLoad like below:-

class General: UILibraryFunction {

override func viewDidLoad() {

    //-- top bar ------
    setTitle(BarTitle: "Header")


Logout button in every viewcontroller in swift 4, I'm new in iOS. I've implemented an login section. Login is working fine. But after login, I'm adding a button (logout) manually. After clicking it, logging out from� To connect the image view to the ViewController.swift code Click the Assistant button in the Xcode toolbar near the top right corner of Xcode to open the assistant editor. If you want more space to work, collapse the project navigator and utility area by clicking the Navigator and Utilities buttons in the Xcode toolbar.

Lecture 16. Log Out and Auto Sign In., @IBAction func logout_TouchUpInside(_ sender: Any) { functionWhichMightFail() }. Now run the app and test the Log Out button. What do you see? (c) As this� In the Main.storyboard file I've added a few buttons and connected them to code (outlets and actions) in the ViewController.swift file by Control/Dragging to the ViewController.swift file. The outlets and actions are added just fine and things seem to work well.

Logout & login does not reissue user token (User Service API, iOS , I have a logout button that makes a call to backendless.user.logout() (and have also tried the async method), and then performs an unwind segue that returns to the login view controller. User token changes every time I'm trying to login/ logout (v 4.0.21) sergey-chupovN0 (Sergey Chupov) August 14, 2018, 3:34pm #5. Every SwiftUI view that represents a UIKit view or view controller undergoes following steps that conclude its lifecycle: Let’s go over each step: Create a custom coordinator instance that manages updates between your view controller or view and other parts of your SwiftUI app. Create an instance of a view controller or a view.

Alerts are crucial when building your app, to ask the user for confirmation of a sensitive action.Deleting data, signing out, giving permission, confirming a change — they’re tasks that your app’s user needs to explicitly confirm before continuing.

  • please see this ; stackoverflow.com/questions/32061540/…
  • @Logic I had already checked that. but it's not same with my problem.
  • I'm working with an big app. Will be minimum 100 view. So working with UINavigationController is not possible.
  • where will I include this code? In AppDelegate? how'll I use it? I'm new in this field..
  • use this code in viewcontroller , when you hit signout button , put this code in function of that button.