Conditionally following a segue

前端 未结 4 1283
北恋
北恋 2020-12-13 20:29

In my app I have a login screen. When connecting a segue from the login button to the next (table) view controller however, you are always able to proceed, no matter what yo

相关标签:
4条回答
  • 2020-12-13 20:32

    On iOS 6, UIViewController's shouldPerformSegueWithIdentifier:sender: method solves this issue without manual triggering segues.

    0 讨论(0)
  • 2020-12-13 20:32

    This is belated, but imo it's best to setEnabled:NO whatever is triggering the segue until the segue is "valid". That separates your segue logic from your view logic....

    0 讨论(0)
  • 2020-12-13 20:36

    You can wire up your login button or whatever to some IBAction code, decide if the login should proceed and then (if it should) you can use performSegueWithIdentifier: to transition to the new view.

    I just wrote another post about using this method, here.

    0 讨论(0)
  • 2020-12-13 20:49
    1. Create a manual segue from "login" to say "dashboard"
    2. Give a name for segue identifier, e.g. "showDashboard"
    3. Wire the "Next" button for IBAction
    4. Manually invoke segue with identifier once all the constraints are met.

    - (IBAction)nextButtonPressed:(id)sender
    {
        if ([self hasAllRequiredFields]) {
            [self performSegueWithIdentifier:@"showDashboard" sender:self];
        } 
    }
    

    0 讨论(0)
提交回复
热议问题