Is it possible to assign ShouldPerformSegue result based on UIAlertController choice?

tanriverditanriverdi USMember ✭✭

Hi all, I want to set return value of ShouldPerformSegue method according to user's choice in a UIAlertController. Is it possible? if not, what else can I do?

Thanks for your time.

Best Answer

  • andnesandnes US ✭✭✭
    Accepted Answer

    ShouldPerformSegue will only be triggered right before a segue (which is declared in your storyboard) is about to be performed. What you could do though is to call PerformSegue in your code based on the result of your UIAlertController. Note that a segue between your source and destination controller needs to be in place for this to work.
    I have done something similar in our app to achieve the same thing so I have some more ideas if this does not work for you.

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    Of course you can do this. You can define a bool property in the ViewController. When user select a choice in the UIAlertController, it will trigger the handler of a UIAlertAction. Set the property there, And you can return this property when user wants to push to another view controller using a segue.

  • tanriverditanriverdi USMember ✭✭

    I think you misunderstood me. I want to present UIAlertController when user pushes to another view controller using a segue. Not before that. I simply want to ask users if they are sure about log off.

  • andnesandnes USMember ✭✭✭
    Accepted Answer

    ShouldPerformSegue will only be triggered right before a segue (which is declared in your storyboard) is about to be performed. What you could do though is to call PerformSegue in your code based on the result of your UIAlertController. Note that a segue between your source and destination controller needs to be in place for this to work.
    I have done something similar in our app to achieve the same thing so I have some more ideas if this does not work for you.

  • tanriverditanriverdi USMember ✭✭

    Hi andnes, it worked thank you. I didn't know calling PerformSegue is that easy :D

Sign In or Register to comment.