I'm trying to set up a login screen (ViewController
) that leads - after a successful login - to a user list (UserTableViewController
) that is itself part of a navigation controller. On the subsequent screens like the UserTableViewController
it should be possible to logout. This would bring the user back to the initial login screen ViewController
. I'm really struggling connecting those screens the right way. It must be said that I don't have a lot of experience with the different kinds of segues and/or delegates so, with some research done, I went for some trials:
- A successful login on
ViewController
triggers a modal-segue to the navigation controller (that itself leads to theUserTableViewController
) - The
UserTableViewController
has a logout button that triggers another modal-segue back to theViewController
. I took these modal segues because first, I didn't want to have a hierarchy that leads to an automatically created back-button or similar and second, I didn't want to have any "troubles" between these two screens, one having a navigation controller while the other one doesn't.
...it looks like that's not a way to go. Some things get mixed up after one loop and screens are changing the wrong way. I guess a modal-segue-circle is not possible as there has to be parent and a child at least. Next trial:
- A successful login on
ViewController
triggers a modal-segue / push-segue to the navigation controller (that itself leads to theUserTableViewController
) - To return to the login screen I implemented a delegate instead of another segue, triggered when tapping "logout" - here I'm facing the problem that I can't set up the
UserTableViewController
's delegate inpreparingForSegue
onViewController
properly. At this pointsegue.destinationViewController
cannot be downcasted toUserTableViewController
but only toNavigationController
what doesn't allow me to set up the delegate at the destination (UserTableViewController
).
The third trial was to do the same like in the second approach but implementing a segue from ViewController
to UserTableViewController
directly. That may work but now I don't have any navigation bar anymore at my UserTableViewController
...!
Of course I could go for a manual fix in the third solution like inserting a stand-alone navigation bar but neither way seems to be efficient. Therefore I'd very very thankful for some hints, highlighting what I misunderstood (completely) on one side and showing a good way of doing it on the other side. Thanks a lot for any help!
EDIT:
I could try to set the navigation controller as initial view controller and then just let the login screen ViewController
being presented/dismissed by the UserTableViewController
- is that a practical way or are there widely known best practices for those login view scenario?
Just a visual help: