Search code examples
iosswiftuiviewcontrolleruitextfieldunwind-segue

IOS modal view from main UIViewController


I am using a segue to present a modal view of a UIViewController that has the same (UIViewController) swift class. In the modal I present a UITextField to capture some user input; Then when I then unwind the segue on the modal to return to the original view, the value is removed from the UITextfield, so I am thinking I am not implementing this correctly (newer swift/xcode developer here).

My question is should I be creating a separate class to attach to each modal view every time, and pass that data back to the originating view controller in the unwind segue? Is there another way to provide a modal UI to the user using the same view controller class context?


Solution

  • I would suggest, create a separate class for your modal view, and pass the data back. Use a protocol!

    This link addresses your question.