Perform Segue After Login Successful in Storyboards

Perform segue after Login successful in Storyboards

You need to drag the segue from the overall UIViewController to the next UIViewController, i.e. you shouldn't specifically connect the UIButton (or any IBOutlet for that matter) to the next UIViewController if the transition's conditional.

Like so:

enter image description here

Performing segue on login success

All operations that affect the UI must be performed on the main queue. Many network operations execute on a background queue and dispatch the completion handler block on that background queue.

A classic symptom of not using the main queue for UI updates is delayed or missing updates.

You can use

DispatchQueue.main.async {
self.performSegue(withIdentifier: "login_success", sender: self)
}

To explicitly dispatch the code on the main queue.

Perform Segue after login check

You can manually perform segues.
When you create a segue in the storyboard, instead of Ctrl+Dragging from a button to a View Controller, drag from the View Controller to another View Controller.
Give the segue a name, then in your code you call [self performseguewithidentifier@"seguename"]

iOS: Make segue wait for login success

Ok, I have figured it out. I had defined a segue from a UIButton to the next UIViewController. As defined in this manner, there is no way to conditionally execute the segue.

Instead of putting the segue on the button, I made a segue from the first UIViewController to the other UIViewController. This defines the segue, but associates no action with it. From there I can simply call performSegueWithIdentifier:sender: when I want that segue to execute (in my case being when the async task is complete).

The main advantage of this for me is that IB maintains its structure.

Big thanks to @cli_hlt for pointing me in the right direction (+1).

How to programmatically segue after successful authentication?

Now I understand the problem more, please try this:

import UIKit
import DigitsKit
class LoginViewController: UIViewController {

override func viewDidLoad() {
let digitsButton = DGTAuthenticateButton(authenticationCompletion: { (session, error) in
if (session != nil) {
print("Your Digits User ID is " + session.userID)
let map = MapVC()
self.presentViewController(map, animated: true, completion: nil)
}
else {
print(error.localizedDescription)
}
})
self.view.addSubview(digitsButton)
}
}

Alternatively can use:

import UIKit
import DigitsKit
class LoginViewController: UIViewController {

override func viewDidLoad() {
let digitsButton = DGTAuthenticateButton(authenticationCompletion: { (session, error) in
if (session != nil) {
print("Your Digits User ID is " + session.userID)
self.performSegueWithIdentifier("mapVC", sender: self)
}
else {
print(error.localizedDescription)
}
})
self.view.addSubview(digitsButton)
}
}

I hope this works :)

Custom segue after successful login

The error is telling you you can't use that type of transition without using a navigation controller.

Simply drag and drop a navigation controller from the right menu and set it as the Initial Controller in the properties section on the right. like so:

enter image description here

Then connect your login controller as its root view controller. Then this will work for you.

The end result should look something like:

enter image description here

perform segue to initial view from any view with Storyboards

Finally I solved the problem changing the observer for isLogged from App Delegate to my custom TabViewController. In viewDidLoad I subscribe to this var.

In method observeValueForKeyPath I do the following:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

LoginViewController *loginController = [storyboard instantiateViewControllerWithIdentifier:@"Login"];

[self presentModalViewController:loginController animated:YES];

How to programmatically segue after successful authentication with Firebase?

The prepare(for:sender:) is not correct. That method is for passing data to the segue.destination view controller, not for initiating a push or whatever. E.g., if your destination view controller was a FooViewController and you wanted to set the bar property in order to pass some data from the current view controller to FooViewController, you would:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? FooViewController {
destination.bar = ...
}
}

But if you don't need to pass any data to the destination view controller, then no prepare(for:sender:) is needed.


In answer to the titular question, if your storyboard has a segue, give that segue an identifier, and then to initiate it programmatically, you would do:

storyboard?.performSegue(withIdentifier: "xxx", sender: self)

Segue is triggered whether credentials are correct or not

You should implement shouldPerformSegueWithIdentifier:sender: method to control whether you want the segue to be performed.



Related Topics



Leave a reply



Submit